package avicit.im.lantop.docmanager.deptdocarrange.action;

import avicit.cbb.appreg.service.CommSysInfoIntfsService;
import avicit.cbb.billdefine.service.BillDefineDynamicService;
import avicit.cbb.billdefine.service.BillDefineManagerIntfsService;
import avicit.cbb.billdefine.service.api.BillDefineDynamicServiceApi;
import avicit.cbb.billdefine.service.api.BillDefineManagerIntfsServiceApi;
import avicit.cbb.fondsmanage.service.CbbFondsDbIntfsService;
import avicit.cbb.tabledefine.service.CommTableManagerIntfsService;
import avicit.cbb.undomessage.service.UndoMessageManagerIntfsService;
import avicit.im.lantop.archiveclassmanager.service.ArchiveClassManagerIntfsService;
import avicit.im.lantop.archivemanager.archivearrange.arrange.service.ArrangeProviderService;
import avicit.im.lantop.archiverelateset.service.ArchiverelatesetIntfsService;
import avicit.im.lantop.basic.archiveclassmanager.domain.LantopArchiveClass;
import avicit.im.lantop.basic.archiveclassmanager.service.ArchiveclassmanagerService;
import avicit.im.lantop.basic.archiveclassmanager.service.api.ArchiveclassmanagerServiceApi;
import avicit.im.lantop.common.StringUtil;
import avicit.im.lantop.common.service.CommonManagerIntfsService;
import avicit.im.lantop.common.service.api.CommonManagerIntfsServiceApi;
import avicit.im.lantop.docmanager.deptdocarrange.service.DeptdocarrangeService;
import avicit.im.lantop.docmanager.deptdocarrange.service.api.DeptdocarrangeServiceApi;
import avicit.im.lantop.docmanager.mydocmanager.domain.LantopFileShare;
import avicit.im.lantop.docmanager.mydocmanager.domain.LantopSubmit;
import avicit.im.lantop.docmanager.mydocmanager.domain.LantopSubmitItem;
import avicit.im.lantop.enclosurexml.dateUtilNew.DateUtilNew;
import avicit.im.lantop.fieldmapset.service.FieldMapSetIntfsService;
import avicit.im.lantop.fourcheckmanager.service.FourCheckService;
import avicit.im.lantop.searchlog.service.LantopSearchLogIntfsService;
import avicit.im.lantop.storeroommanager.service.StoreroommanagerIntfsService;
import avicit.im.lantop.userauthset.service.UserAuthIntfsService;
import avicit.platform6.api.application.SysApplicationAPI;
import avicit.platform6.api.commonpopup.CommonSelectionAPI;
import avicit.platform6.api.commonpopup.dto.Node;
import avicit.platform6.api.session.SessionHelper;
import avicit.platform6.api.syslookup.SysLookupAPI;
import avicit.platform6.api.syslookup.dto.SysLookupSimpleVo;
import avicit.platform6.api.syslookup.impl.SysLookupAPImpl;
import avicit.platform6.api.sysmenu.SysMenuAPI;
import avicit.platform6.api.sysmenu.dto.SysMenu;
import avicit.platform6.api.sysshirolog.impl.AfterLoginSessionProcess;
import avicit.platform6.api.sysuser.*;
import avicit.platform6.api.sysuser.dto.SysDept;
import avicit.platform6.api.sysuser.dto.SysOrg;
import avicit.platform6.api.sysuser.dto.SysRole;
import avicit.platform6.api.sysuser.dto.SysUser;
import avicit.platform6.api.sysuser.impl.SysDeptAPImpl;
import avicit.platform6.api.sysuser.impl.SysUserAPImpl;
import avicit.platform6.bpm.web.service.BpmOperateService;
import avicit.platform6.commons.utils.DateUtil;
import avicit.platform6.commons.utils.JsonHelper;
import avicit.platform6.commons.utils.JsonUtil;
import avicit.platform6.commons.utils.JsonUtils;
import avicit.platform6.commons.utils.web.TreeNode;
import avicit.platform6.core.domain.BeanProcess;
import avicit.platform6.core.jdbc.JdbcAvicit;
import avicit.platform6.core.properties.PlatformConstant.OpResult;
import avicit.platform6.core.rest.client.RestClient;
import avicit.platform6.core.rest.client.RestClientConfig;
import avicit.platform6.core.rest.msg.Muti1Bean;
import avicit.platform6.core.rest.msg.Muti3Bean;
import avicit.platform6.core.rest.msg.ResponseMsg;
import avicit.platform6.core.spring.SpringFactory;
import avicit.platform6.generic.constant.CommonFunction;
import avicit.platform6.generic.constant.VariableClass;
import avicit.platform6.generic.sqls.SqlAllClass;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.ws.rs.core.GenericType;
import java.io.IOException;
import java.net.URLDecoder;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * <p>金航数码科技有限责任公司</p>
 * <p>作者：钟一华</p>
 * <p>邮箱：feifan1985@163.com</p>
 * <p>创建时间： 2014-10-24 上午10:29:37 </p>
 * <p>类说明：部门文件管理控制层</p>
 * <p>修改记录： </p>
 */
@Controller
@SuppressWarnings({"unchecked", "deprecation"})
@RequestMapping("/deptdocarrangeController")
public class DeptdocarrangeController {

    private SysUserAPI userLoader = SpringFactory.getBean(SysUserAPImpl.class);

    private SysDeptAPI deptLoader = SpringFactory.getBean(SysDeptAPImpl.class);

    private SysRoleAPI roleLoader = SpringFactory.getBean(SysRoleAPI.class);
    @Autowired
    private CommonSelectionAPI commonSelectionAPI;

    @Autowired
    private SysUserDeptPositionAPI sysUserDeptPositionAPI;

//    @Autowired(required = true)
//    private UndoMessageManagerIntfsService undoMessageManagerIntfsService;

    @Autowired(required = true)
    private SysApplicationAPI sysApplicationAPI;

    @Autowired(required = true)
    private CommonManagerIntfsServiceApi commonManagerIntfsServiceImpl;

    @Autowired(required = true)
    private BillDefineDynamicServiceApi billDefineDynamicService;

    @Autowired(required = true)
    private CbbFondsDbIntfsService cbbFondsDbIntfsService;

    @Autowired(required = true)
    private DeptdocarrangeServiceApi deptdocarrangeService;

    @Autowired(required = true)
    private ArchiveClassManagerIntfsService archiveClassManagerIntfsService;

    @Autowired(required = true)
    private ArchiveclassmanagerServiceApi archiveclassmanagerService;

    @Autowired(required = true)
    private BillDefineManagerIntfsServiceApi billDefineManagerIntfsService;

//    @Autowired(required = true)
//    private CommSysInfoIntfsService commSysInfoIntfsService;

    @Autowired(required = true)
    private CommTableManagerIntfsService commTableManagerIntfsService;

//    @Autowired(required = true)
//    private FieldMapSetIntfsService fieldMapSetIntfsService;

    @Autowired(required = true)
    private UserAuthIntfsService userAuthIntfsService;

//    @Autowired(required = false)
//    private ArchiverelatesetIntfsService archiverelatesetIntfsService;

//    @Autowired(required = false)
//    private StoreroommanagerIntfsService storeroommanagerIntfsService;

//    @Autowired
//    private LantopSearchLogIntfsService lantopSearchLogIntfsService;

    @Autowired(required = true)
    private SysMenuAPI menuAPI;

    @Autowired(required = true)
    private SysOrgAPI sysOrgAPI;

    @Autowired(required = true)
    private JdbcAvicit jdbcAvicit;

    private String menuCode;

    private String sysFlag;

    private SysLookupAPI upLoader = SpringFactory.getBean(SysLookupAPImpl.class); // 加载通用代码对象

    //SanXiaFiles add by huangjain 四性检测相关业务层
//    @Autowired
//    private FourCheckService fourCheckService;

    @Autowired
    private SysDeptAPI sysDeptAPI;

    /**
     * 跳转个人文件著录主页面
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     */
    @RequestMapping("/toDeptDocArrangeManager")
    public ModelAndView toDeptDocArrangeManager(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String sysId = request.getParameter("sysId");
        sysId = "LANTOP";
        this.sysFlag = request.getParameter("sysFlag");
        this.menuCode = request.getParameter("menuCode");
        mav.addObject("sysId", sysId);
        mav.addObject("sysFlag", sysFlag);
        mav.addObject("menuCode", menuCode);
        mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeManager");
        return mav;
    }

    /**
     * 初始化树节点方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/initFileTreeNode")
    public ModelAndView initFileTreeNode(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String userId = SessionHelper.getLoginSysUserId(request);
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        // String ip = SessionHelper.getClientIp(request);
        String sysId = request.getParameter("sysId");
        String BS = request.getParameter("BS");
        List<TreeNode> nodes = new ArrayList<TreeNode>();
        // String appId = SessionHelper.getApplicationId();
        try {
            // 获取部门信息
            List<SysDept> sds = deptLoader.getAllSysDeptList();
            List<String> deptIdList = new ArrayList<String>();
            for (int i = 0; i < sds.size(); i++) {
                deptIdList.add(sds.get(i).getId());
            }
            // 获取档案管人员角色信息
            // SysRole sr = roleLoader.getSysRoleByRoleCode("lantop_archive_user");
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("targetId", userId);
            param.put("targetType", "3");
            param.put("sysId", sysId);
            param.put("orgId", orgId);
            String pid = request.getParameter("id");// 树的节点id
            param.put("rootId", pid);
            param.put("orgIdentity", SessionHelper.getCurrentOrgIdentity(request));
            if(!"".equals(BS)){
                nodes = archiveClassManagerIntfsService.getArchiveClassTreeNodeToDataNodeInfoByIntfsforZLGD(orgId, deptId, sysId, "2", param);
            }else{
                nodes = archiveClassManagerIntfsService.getArchiveClassTreeNodeToDataNodeInfoByIntfs(orgId, deptId, sysId, "2", param);
            }
            mav.addObject("data", nodes);
            mav.addObject("result", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("result", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 整理归档专用
     * @MethodName: initFileTreeNode
     * @param request
 * @param response
     * @Return: org.springframework.web.servlet.ModelAndView
     * @Author: 无量
     * @Date: 2019/9/28 17:37
     */
    @RequestMapping("/initFileTreeNodeforZLGD")
    public ModelAndView initFileTreeNodeforZLGD(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String userId = SessionHelper.getLoginSysUserId(request);
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        // String ip = SessionHelper.getClientIp(request);
        String sysId = request.getParameter("sysId");
        List<TreeNode> nodes = new ArrayList<TreeNode>();
        // String appId = SessionHelper.getApplicationId();
        try {
            // 获取部门信息
            List<SysDept> sds = deptLoader.getAllSysDeptList();
            List<String> deptIdList = new ArrayList<String>();
            for (int i = 0; i < sds.size(); i++) {
                deptIdList.add(sds.get(i).getId());
            }
            // 获取档案管人员角色信息
            // SysRole sr = roleLoader.getSysRoleByRoleCode("lantop_archive_user");
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("targetId", userId);
            param.put("targetType", "3");
            param.put("sysId", sysId);
            param.put("orgId", orgId);
            String pid = request.getParameter("id");// 树的节点id
            param.put("rootId", pid);
            param.put("orgIdentity", SessionHelper.getCurrentOrgIdentity(request));
            nodes = archiveClassManagerIntfsService.getArchiveClassTreeNodeToDataNodeInfoByIntfsforZLGD(orgId, deptId, sysId, "2", param);

            mav.addObject("data", nodes);
            mav.addObject("result", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("result", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 树查询方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/searchTreeNode")
    public ModelAndView searchTreeNode(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String value = request.getParameter("value");
        if (value != null && !"".equals(value)) {
            value = URLDecoder.decode(value, "UTF-8");
        }
        mav.setView(null);
        List<TreeNode> nodes = new ArrayList<TreeNode>();
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String userId = SessionHelper.getLoginSysUserId(request);
        try {
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("archiveType", "2");
            param.put("searchValue", value);
            param.put("targetId", userId);
            if (null != this.sysFlag && "JTB".equals(this.sysFlag)) {
                param.put("jtbFlag", "JTB_BMWJ");
            }
            nodes = this.archiveClassManagerIntfsService.getArchiveClassTreeNodeToSearchByIntfs(orgId, deptId, sysId, param);
            mav.addObject("data", nodes);
            mav.addObject("result", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("result", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * SanXiaFiles create by zhaoxiaolong 校验当前登录用户是否为专职档案管理员，true 是，false 否
     * @param userId
     * @param userCode
     * @return
     */
    private boolean isSanXiaManageRole(String userId,String userCode){
        boolean isSanXiaManageRole = false;
        StringBuffer sbSql = new StringBuffer();
        sbSql.append("SELECT\n" +
                "\tCOUNT( 1 ) COUNT \n" +
                "FROM\n" +
                "\tSYS_USER_ROLE SYR\n" +
                "\tLEFT JOIN SYS_ROLE SR ON SR.ID = SYR.SYS_ROLE_ID \n" +
                "WHERE\n" +
                "\tSR.ROLE_CODE = '"+userCode+"' \n" +
                "\tAND SYR.SYS_USER_ID = '"+userId+"'");
        List<Map<String,Object>> countList = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString());
        if (countList!=null&&countList.size()>0){
            int count = Integer.valueOf(countList.get(0).get("COUNT").toString());
            if(count>0){
                isSanXiaManageRole = true;
                return isSanXiaManageRole;
            }else {
                return isSanXiaManageRole;
            }
        }else {
            return isSanXiaManageRole;
        }
    }

    /**
     * 获得节点对应物理表信息
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getTableInfo")
    public ModelAndView getTableInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
            String id = request.getParameter("id");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String menuCode = request.getParameter("menuCode");

        this.sysFlag = request.getParameter("sysFlag");
        // 节点父级类型 2档案类型
        String parentType = request.getParameter("parentType");
        request.setAttribute("parentType", parentType);
//        sysId = this.commSysInfoIntfsService.getSysIdByIntfs(sysId);
        String userId = SessionHelper.getLoginSysUserId(request);
        String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
        SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
        String orgCode = so.getOrgCode();
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("currentUserId", userId);
        param.put("currentDeptId", deptId);
        param.put("currentOrgCode", orgCode);
        param.put("nodeId", id);
        Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
        param.put("languageCode", sessionLanguageCode);
        //SanXiaFiles update by huangjian start
        param.put("archiveFlag", "1");//1、整理归档，2著录整理，3馆藏
        //SanXiaFiles update by huangjian end
        String loginUserSecretLevel = SessionHelper.getLoginSysUser(request).getSecretLevel();
        Map<String, Object> pa = new HashMap<String, Object>();
        pa.put("languageCode", sessionLanguageCode);
        pa.put("userSecretLevel", loginUserSecretLevel);

        String share = request.getParameter("share");
        // 张坚修改内容：用于处理跳转到文件公共选择页
        // begin
        String openType = request.getParameter("openType");
        String viewName = "";
        if (null != openType && openType.equals("selectFile")) {
            // 文件选择页
            viewName = "avicit/im/lantop/docmanager/mydocmanager/commonSelect/mydocmanagerIframe";
        } else {
            // 模块自身页面
            viewName = "avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeIframe";
        }
        // end

        // 角色/用户过滤条件
        // 获取兼职档案员角色信息
        SysRole sr = roleLoader.getSysRoleByRoleCode("LANTOP_PART-TIME_ARCHIVISTS");
        String appId = SessionHelper.getApplicationId();
        // 是否是文书立卷人角色
        boolean isArchiveUser = false;
        if (null != sr) {
            // 根据用户id获取角色信息
            List<SysRole> srs = roleLoader.getRolesByUserId(userId, appId);
            for (int i = 0; i < srs.size(); i++) {
                SysRole role = srs.get(i);
                if (sr.getId().equals(role.getId())) {
                    isArchiveUser = true;
                    break;
                }
            }
        }


        // SanXiaFiles create by zhaoxiaolong 获取当前登录人的角色信息
        String userRoleCode = ""; // 角色编码
        int queryDimension = 0 ; // 查询SQL维度
        Map<String,Object> roleCodeMap = userAuthIntfsService.isRole(SessionHelper.getLoginSysUserId(request),orgCode,orgId);
        if(roleCodeMap.size()>0&&roleCodeMap!=null){
            userRoleCode = (String) roleCodeMap.get("userRoleCode");
        }
        if (userRoleCode.indexOf("_Sanxia_Manager_ROLE")!=-1){ // 如果是专职档案管理员 queryDimension = 0
            mav.addObject("queryDimension",queryDimension);
        }else { // 是否为兼职档案管理员
            if (userRoleCode.indexOf("_Parttime_Manager_ROLE")!=-1){
                queryDimension = 1;
                mav.addObject("queryDimension",queryDimension);
            }else if(userRoleCode.indexOf("_Comm_User_ROLE")!=-1){ // 其他角色
                queryDimension = 2;
                String guanlianDimension = "COMM_USER_ROLE";
                mav.addObject("queryDimension",queryDimension);
                mav.addObject("guanlianDimension",guanlianDimension);
            }else {
                queryDimension = 2;
                mav.addObject("queryDimension",queryDimension);
            }
        }
        try {
            String isParent = "";
            // 所选节点对应物理表信息
            List<Map<String, Object>> allList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, id, "");
            if (allList.size() == 0) {
                isParent = id;
                List<Map<String, Object>> nodeList = this.deptdocarrangeService.getChildNodeIdByParentId(id);
                if (nodeList.size() > 0) {
                    Map<String, Object> map = nodeList.get(nodeList.size() - 1);
                    id = map.get("ID").toString();
                }
                allList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, id, "");
            }
            if (allList.size() == 1) {
                // 文件目录标签页物理表信息
                List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, id, "1");
                Map<String, Object> fileMap = fileList.get(0);
                String fileId = fileMap.get("ID").toString();
                String fileTableName = fileMap.get("TABLE_NAME").toString();

                /******2019-05-24 yangzengzhi 科研档案 关联按钮显示********/
                if (fileTableName.equals("LANTOP_KYDA_WJ")) {
                    mav.addObject("projectFlag", "KYDA");
                }

                // 文件动态查询字段集合
                //SanXiaFiles update by huangjian 如果是档案类型单独走业务查询字段 start
                List<Map<String, Object>> fileSearchList = null;
                if ("2".equals(parentType)) {//如果是档案类型
                    //SanXiaFiles update by huangjian
                    param.put("archiveFlag", "1");//3馆藏，2著录整理  1整理归档
                    fileSearchList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfsItera(orgId, deptId, sysId, fileId, "4", "", param);
                } else {
                    fileSearchList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, fileId, "4", "", param);
                }
                //SanXiaFiles update by huangjian 如果是档案类型单独走业务查询字段 end
                // 文件动态显示字段集合
                List<Map<String, Object>> fileTableList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, fileId, "2", "", param);
                String fileDeptCols = this.billDefineManagerIntfsService.getSelectDialogStringByIntfs(orgId, deptId, sysId, fileId); // 查找选部门，选人的字段字符串
                Map<String, Map<String, String>> fileMapCode = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, fileId, "", "4", pa);// 获取字段通用代码数据//
                // 查找字段生成方式为通用代码的集合
                mav.addObject("fileTableSize", fileTableList.size());
                mav.addObject("fileTableName", fileTableName);
                mav.addObject("fileMapCode", fileMapCode);
                mav.addObject("fileDeptCols", fileDeptCols);
                mav.addObject("fileTableId", fileId);
                mav.addObject("fileSearchList", fileSearchList);
                mav.addObject("fileTableList", fileTableList);

                Map<String, Object> colFileMap = new HashMap<String, Object>();
                colFileMap.put("tableId", fileId);
                //SanXiaFiles update by huangjian 2019-07-14  文件级目录也可以有粘贴功能
                mav.addObject("anTableId", fileId);
                colFileMap.put("nodeId", id);
                colFileMap.put("sysId", sysId);
                colFileMap.put("flag", "4");
                colFileMap.put("orgId", orgId);
                colFileMap.put("deptId", deptId);
                Map<String, Object> dynamicFileMap = this.commTableManagerIntfsService.getColumnPageMap(colFileMap);
                dynamicFileMap.put("MODEL_CODE", "mydocmanagerFile");
                dynamicFileMap.put("FORM_CODE", "searchFileForm");
                dynamicFileMap.put("ALIAS_NAME", "FILE");
                String searchFileHtml = this.billDefineDynamicService.getDynamicSearchHtml(fileSearchList, fileMapCode, dynamicFileMap);
                mav.addObject("searchFileHtml", searchFileHtml);
                List<Map<String, Object>> colList = new ArrayList<Map<String, Object>>();
                Map<String, Object> htmlParam = new HashMap<String, Object>();
                htmlParam.put("datagridId", "fileDatagrid");
                htmlParam.put("datagridUrl", "");
                htmlParam.put("datagridToolbarId", "searchFileDiv");
                htmlParam.put("domainObjectParam", "deptdocarrange_deptdocarrangeIframe_fileDatagrid"); // 模块名_jsp名_tableid
                htmlParam.put("colList", colList); // 固定列参数
                htmlParam.put("tabColList", fileTableList); // 对应显示字段
                // add by zyh
                // 自定义初始化字段设置格式化方法,题名字段
                Map<String, String> currentFormatter = new HashMap<String, String>();
                currentFormatter.put("TM", "formatTmDetail");
                //SanXiaFiles update by huangjian 格式化文件级 四性检测状态
                currentFormatter.put("FOUR_STATE", "formatFourStateByFile");

                //xmw 格式化是否关联计划
                currentFormatter.put("PLAN_STATE", "formatSFGL");

                htmlParam.put("CURRENT_FORMATTER", currentFormatter);
                // add by zyh
                String fileDatagridHtml = this.billDefineDynamicService.getDatagridHtml(htmlParam);
                mav.addObject("fileDatagridHtml", fileDatagridHtml);
                Map<String, Object> htmlParam1 = new HashMap<String, Object>();
                htmlParam1.put("datagridId", "fileDatagrid1");
                htmlParam1.put("datagridUrl", "");
                htmlParam1.put("datagridToolbarId", "searchFileDiv1");
                htmlParam1.put("domainObjectParam", "deptdocarrange_deptdocarrangeIframe_fileDatagrid1"); // 模块名_jsp名_tableid
                htmlParam1.put("colList", colList); // 固定列参数
                htmlParam1.put("tabColList", fileTableList); // 对应显示字段
                htmlParam1.put("CURRENT_FORMATTER", currentFormatter);
                String fileDatagridHtml1 = this.billDefineDynamicService.getDatagridHtml(htmlParam1);
                mav.addObject("fileDatagridHtml1", fileDatagridHtml1);
                // 区分案卷级和文件级 1 文件 2案卷 SanxiaFiles create by zhaoxiaolong
                mav.addObject("level", "1");
            }
            if (allList.size() >= 2) {
                // 文件目录标签页物理表信息
                List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, id, "2");
                Map<String, Object> fileMap = fileList.get(0);
                String fileId = fileMap.get("ID").toString();
                String fileTableName = fileMap.get("TABLE_NAME").toString();
                /******2019-05-24 yangzengzhi 科研档案 关联按钮显示********/
                if (fileTableName.equals("LANTOP_KYDA_WJ")) {
                    mav.addObject("projectFlag", "KYDA");
                }

                // 文件动态查询字段集合
                List<Map<String, Object>> fileSearchList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, fileId, "4", "", param);
                // 文件动态显示字段集合
                List<Map<String, Object>> fileTableList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, fileId, "2", "", param);

                //SanXiaFiles update by huangjian start 零散文件去掉四性检测状态
                List<Map<String, Object>> fileScatteredList = new ArrayList<>();
                fileScatteredList.addAll(fileTableList);
                for (Map<String, Object> fileCol : fileScatteredList) {
                    if("FOUR_STATE".equalsIgnoreCase(String.valueOf(fileCol.get("COL_NAME")))){
                        fileScatteredList.remove(fileCol);//零散文件去掉四性检测状态
                        break;
                    }
                }
                //SanXiaFiles create by huagjian end

                String fileDeptCols = this.billDefineManagerIntfsService.getSelectDialogStringByIntfs(orgId, deptId, sysId, fileId); // 查找选部门，选人的字段字符串
                Map<String, Map<String, String>> fileMapCode = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, fileId, "", "4", pa);// 获取字段通用代码数据//
                mav.addObject("fileTableName", fileTableName);
                mav.addObject("fileMapCode", fileMapCode);
                mav.addObject("fileDeptCols", fileDeptCols);
                mav.addObject("fileTableId", fileId);
                mav.addObject("fileSearchList", fileSearchList);
                mav.addObject("fileTableList", fileTableList);
                mav.addObject("fileTableSize", fileTableList.size());

                Map<String, Object> colFileMap = new HashMap<String, Object>();
                colFileMap.put("tableId", fileId);
                colFileMap.put("nodeId", id);
                colFileMap.put("sysId", sysId);
                colFileMap.put("flag", "4");
                colFileMap.put("orgId", orgId);
                colFileMap.put("deptId", deptId);
                Map<String, Object> dynamicFileMap = this.commTableManagerIntfsService.getColumnPageMap(colFileMap);
                dynamicFileMap.put("MODEL_CODE", "mydocmanagerFile");
                dynamicFileMap.put("FORM_CODE", "searchFileForm");
                dynamicFileMap.put("ALIAS_NAME", "FILE");
                String searchFileHtml = this.billDefineDynamicService.getDynamicSearchHtml(fileSearchList, fileMapCode, dynamicFileMap);
                mav.addObject("searchFileHtml", searchFileHtml);
                List<Map<String, Object>> colList = new ArrayList<Map<String, Object>>();
                Map<String, Object> htmlParam = new HashMap<String, Object>();
                htmlParam.put("datagridId", "fileDatagrid");
                htmlParam.put("datagridUrl", "");
                htmlParam.put("datagridToolbarId", "searchFileDiv");
                htmlParam.put("domainObjectParam", "deptdocarrange_deptdocarrangeIframe_fileDatagrid"); // 模块名_jsp名_tableid
                htmlParam.put("colList", colList); // 固定列参数
                //htmlParam.put("tabColList", fileTableList); // 对应显示字段
                htmlParam.put("tabColList", fileScatteredList); // 对应显示字段
                // add by zyh
                // 自定义初始化字段设置格式化方法
                Map<String, String> currentFormatter = new HashMap<String, String>();
                currentFormatter.put("TM", "formatTmDetail");
                /*添加是否关联组织*/
                currentFormatter.put("GCXMJDID", "formatGcxm");
                currentFormatter.put("PLAN_STATE", "formatSFGL");
                htmlParam.put("CURRENT_FORMATTER", currentFormatter);
                // add by zyh
                String fileDatagridHtml = this.billDefineDynamicService.getDatagridHtml(htmlParam);
                // fileDatagridHtml = fileDatagridHtml.replace("]",",500]");
                mav.addObject("fileDatagridHtml", fileDatagridHtml);

                // 案卷目录标签页物理表信息
                List<Map<String, Object>> anList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, id, "1");
                Map<String, Object> anMap = anList.get(0);
                String anId = anMap.get("ID").toString();
                String anTableName = anMap.get("TABLE_NAME").toString();
                // 案卷动态查询字段集合
                List<Map<String, Object>> anSearchList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, anId, "4", "", param);
                // 案卷动态显示字段集合
                List<Map<String, Object>> anTableList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, anId, "2", "", param);
                String anDeptCols = this.billDefineManagerIntfsService.getSelectDialogStringByIntfs(orgId, deptId, sysId, anId); // 查找选部门，选人的字段字符串
                Map<String, Map<String, String>> anMapCode = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, anId, "", "4", pa);// 获取字段通用代码数据//

                Map<String, Object> colErMap = new HashMap<String, Object>();
                colErMap.put("tableId", anId);
                colErMap.put("nodeId", id);
                colErMap.put("sysId", sysId);
                colErMap.put("flag", "4");
                colErMap.put("orgId", orgId);
                colErMap.put("deptId", deptId);
                Map<String, Object> dynamicErMap = this.commTableManagerIntfsService.getColumnPageMap(colErMap);

                dynamicErMap.put("MODEL_CODE", "mydocmanagerAn");
                dynamicErMap.put("FORM_CODE", "searchAnForm");
                dynamicErMap.put("ALIAS_NAME", "AN");
                String searchErHtml = this.billDefineDynamicService.getDynamicSearchHtml(anSearchList, anMapCode, dynamicErMap);
                mav.addObject("searchAnHtml", searchErHtml);
                List<Map<String, Object>> colListAn = new ArrayList<Map<String, Object>>();
                Map<String, Object> htmlParamAn = new HashMap<String, Object>();
                htmlParamAn.put("datagridId", "mainDatagrid");
                htmlParamAn.put("datagridUrl", "");
                htmlParamAn.put("datagridToolbarId", "tabsToolsAn");
                htmlParamAn.put("domainObjectParam", "deptdocarrange_deptdocarrangeIframe_mainDatagrid"); // 模块名_jsp名_tableid
                htmlParamAn.put("colList", colListAn); // 固定列参数
                htmlParamAn.put("tabColList", anTableList); // 对应显示字段
                // add by zyh
                // 自定义初始化字段设置格式化方法
                Map<String, String> currentAnFormatter = new HashMap<String, String>();
                currentAnFormatter.put("TM", "formatTmAnDetail");
                currentAnFormatter.put("GCXMJDID", "formatGcxm");
                //SanXiaFiles update by huangjian 格式化案卷级 四性检测状态
                currentAnFormatter.put("FOUR_STATE", "formatFourStateByAn");
                htmlParamAn.put("CURRENT_FORMATTER", currentAnFormatter);
                // add by zyh
                String anMDatagridHtml = this.billDefineDynamicService.getDatagridHtml(htmlParamAn);
                // anMDatagridHtml = anMDatagridHtml.replace("]",",500]");
                mav.addObject("anMDatagridHtml", anMDatagridHtml);

                List<Map<String, Object>> colListAnC = new ArrayList<Map<String, Object>>();
                Map<String, Object> htmlParamAnC = new HashMap<String, Object>();
                htmlParamAnC.put("datagridId", "childDatagrid");
                htmlParamAnC.put("datagridUrl", "");
                htmlParamAnC.put("datagridToolbarId", "tabsToolsChildFile");
                htmlParamAnC.put("domainObjectParam", "deptdocarrange_deptdocarrangeIframe_childDatagrid"); // 模块名_jsp名_tableid
                htmlParamAnC.put("colList", colListAnC); // 固定列参数
                htmlParamAnC.put("tabColList", fileTableList); // 对应显示字段
                // add by zyh
                // 自定义初始化字段设置格式化方法
                Map<String, String> currentAnFileFormatter = new HashMap<String, String>();
                currentAnFileFormatter.put("TM", "formatTmDetail");
                currentAnFileFormatter.put("GCXMJDID", "formatGcxm");
                currentAnFileFormatter.put("PLAN_STATE", "formatSFGL");
                //SanXiaFiles update by huangjian 格式化卷内件 四性检测状态
                currentAnFileFormatter.put("FOUR_STATE", "formatFourStateByAnFile");
                htmlParamAnC.put("CURRENT_FORMATTER", currentAnFileFormatter);
                // add by zyh
                String anCDatagridHtml = this.billDefineDynamicService.getDatagridHtml(htmlParamAnC);
                // anCDatagridHtml = anCDatagridHtml.replace("]",",500]");
                mav.addObject("anCDatagridHtml", anCDatagridHtml);

                mav.addObject("anTableName", anTableName);
                mav.addObject("anMapCode", anMapCode);
                mav.addObject("anDeptCols", anDeptCols);
                mav.addObject("anTableId", anId);
                mav.addObject("anSearchList", anSearchList);
                mav.addObject("anTableList", anTableList);
                mav.addObject("anTableSize", anTableList.size());
                // 区分案卷级和文件级 1 文件 2案卷 SanxiaFiles create by zhaoxiaolong
                mav.addObject("level", "2");

            }
            //判断是否属于科技类元数据
            if (allList != null && allList.size() > 0) {
                String kjltablename = "";
                String kjltablenameAj = "";

                for (Map<String, Object> map : allList) {
                    String str = map.get("TABLE_NAME") == null ? "" : map.get("TABLE_NAME").toString();
                    Boolean bool = deptdocarrangeService.isKJLSourceData(str, "GCXMJDID");
                    if (bool) {
                        if ("AJJ".equals(str.substring(str.length() - 3, str.length()))) {
                            mav.addObject("kydaAJ", 1);
                        } else {
                            mav.addObject("kyda", 1);
                        }
                    }
                }
            }
            this.menuCode = menuCode;
            mav.addObject("isArchiveUser", isArchiveUser);
            mav.addObject("isParent", isParent);
            mav.addObject("nodeId", id);
            mav.addObject("orgId", orgId);
            mav.addObject("deptId", deptId);
            mav.addObject("sysId", sysId);
            mav.addObject("sysFlag", sysFlag);
            mav.addObject("allList", allList);
            mav.addObject("share", share);
            mav.setViewName(viewName);
            mav.addObject("attachRecordIdKey", "ID");
            mav.addObject("attachNodeIdKey", "NODE_ID");
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 文件分发
     * 查看当前登录人所在全宗的所有部门
     *
     */
    @RequestMapping("/goToUpdateGddwJsp")
    public ModelAndView goToUpdateGddwJsp(HttpServletRequest request){
        String orgId = SessionHelper.getCurrentOrgId(request);
        SysOrg sysOrg = sysOrgAPI.getSysOrgBySysOrgId(orgId);
        String languageCode = SessionHelper.getCurrentLanguageCode();
        String orgName = sysOrgAPI.getSysOrgNameBySysOrgId(orgId,languageCode);
        SysUser sysUser = SessionHelper.getLoginSysUser(request);
        ModelAndView param = new ModelAndView();
        ModelAndView result = new ModelAndView();    //定义存放过滤后的结果
        String dialogId = request.getParameter("dialogId");// 面板ID
        String ids = request.getParameter("ids");//条目ID集合 多个用逗号隔开
        String tableName = request.getParameter("fileTableName");//表英文名称
        String currentOrgIdentity = SessionHelper.getCurrentOrgIdentity(request);



        param.addObject("dialogId",dialogId);
        param.addObject("ids",ids);
        param.addObject("tableName",tableName);
        param.addObject("orgName",orgName);

        result.addObject("dialogId",dialogId);
        result.addObject("ids",ids);
        result.addObject("tableName",tableName);
        result.addObject("orgName",orgName);
        // param.addObject("userList",allSysUsers);
        Muti3Bean arg = new Muti3Bean();
        Map<String,Object> parameter = new HashMap<>();
        String selectType = "dept";
        arg.setDto1(languageCode);
        arg.setDto2(selectType);
        arg.setDto3(parameter);
        String url = RestClientConfig.getRestHost("sysuser") + "/api/platform6/commonselectionjsp/CommonSelectionJsp/getMutilOrgTree/v1";
        Node node = (Node) RestClient.doPost(url, arg, new GenericType<ResponseMsg<Node>>() {
        }).getResponseBody();
        List<Node> nodes = new ArrayList<>();      //定义存放节点的集合
        //得到当前登录人所在全宗的所有部门
        for (Node child : node.getChildren().get(0).getChildren()) {
            if (child.getId().equals(currentOrgIdentity)){
                nodes.add(child);
            }
        }

        if(currentOrgIdentity.equals("ORG_ROOT")){
            for (Node child : node.getChildren().get(0).getChildren()) {
                if (child.getIconCls().equals("icon-dept") ){
                    nodes.add(child);
                }

            }
        }
        String orgDatajson = JSONArray.toJSON(nodes).toString();
//        String orgDeptJson = this.jsonObjectToString(node);
//        param.addObject("orgDatajson",orgDeptJson);
        result.addObject("orgDatajson",orgDatajson);
//        param.setViewName("avicit/im/lantop/filerecever/OnlineFolderUpdateGddwPage");
//        result.setViewName("avicit/im/lantop/filerecever/OnlineFolderUpdateGddwPage");
        result.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeUpdateGddwPage");
        return result;
    }

    /**
     * 文件
     * 更新归档单位信息
     */
    @RequestMapping("/updateGddwInfo")
    public Map<String, Object> updateGddwInfo(HttpServletRequest request){
        ModelAndView mav = new ModelAndView();
        String ids = request.getParameter("ids");//条目ID集合 多个用逗号隔开
        String tableName = request.getParameter("tableName");//表英文名称
        String deptId = request.getParameter("deptId");//归档单位ID
        String orgId = request.getParameter("orgId");//组织ID
        String tableId = request.getParameter("tableId");
        String deptName = sysDeptAPI.getSysDeptTl(deptId, "zh_CN").getDeptName();
        Map<String, Object> result = deptdocarrangeService.updateGddwInfoByIds(ids, tableId, deptId, orgId,deptName);
        return result;
    }

    /**
     * 文件目录跳转add页面
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/toAddFileJsp")
    public ModelAndView toAddFileJsp(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String id = request.getParameter("id");
        String mid = request.getParameter("mid");
        String num = request.getParameter("num");
        String anTableId = request.getParameter("anTableId");
        String dialogId = request.getParameter("dialogId");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String isKYDA = request.getParameter("isKYDA");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String userId = SessionHelper.getLoginSysUserId(request);
        String dataSecret = request.getParameter("dataSecret");
        String zlzt = request.getParameter("zlzt");//著录状态 1：待整理 2：整理中
        String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
        SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
        String archiveType = request.getParameter("archiveType");
        String parentType = request.getParameter("parentType");//2档案类型
        mav.addObject("parentType", parentType);
        String orgCode = so.getOrgCode();
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("currentUserId", userId);
        param.put("currentDeptId", deptId);
        param.put("currentOrgCode", orgCode);
        param.put("nodeId", nodeId);
        Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
        param.put("languageCode", sessionLanguageCode);


        if (parentType==null || "".equals(parentType) || "null".equals(parentType)){
            parentType = this.billDefineManagerIntfsService.getArchiveTypeByNodeIdAndTableId(orgId, sysId, nodeId, tableId);
        }


        String loginUserSecretLevel = SessionHelper.getLoginSysUser(request).getSecretLevel();
        Map<String, Object> pa = new HashMap<String, Object>();
        pa.put("languageCode", sessionLanguageCode);
        pa.put("userSecretLevel", loginUserSecretLevel);
        try {
            if (null != mid && !"".equals(mid)) {
                Map<String, Object> parentMap = new HashMap<String, Object>();
                parentMap.put("dataId", mid);
                param.put("parentDataId", mid);
                param.put("ortherMap", parentMap);
            } else {
                // 判断是否有父级数据,如果没有,则添加父级密级为max,文件添加时则不进行父级数据和子级数据的密级验证
                dataSecret = "max";
            }
            // List<Map<String, Object>> addFileFieldList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, tableId, "1", id, param);
            //SanXiaFiles update by huangjian start
            List<Map<String, Object>> addFileFieldList = null;
            if ("2".equals(parentType)) {
                param.put("archiveFlag", "1");// 预归档类型
                addFileFieldList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfsItera(orgId, deptId, sysId, tableId, "1", id, param);
            } else {
                addFileFieldList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, tableId, "1", id, param);
            }
            //SanXiaFiles update by huangjian end

            String deptCols = this.billDefineManagerIntfsService.getSelectDialogStringByIntfs1(orgId, deptId, sysId, tableId); // 查找选部门，选人的字段字符串
            Map<String, Map<String, String>> mapCode = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, tableId, "", "1", pa);// 获取字段通用代码数据//
            net.sf.json.JSONArray ja = net.sf.json.JSONArray.fromObject(addFileFieldList);
            String jaString = ja.toString();
            mav.addObject("dataJson", jaString);
            /***** 2016/04/13增加 wangzp 页面动态显示 *****/
            // List<Map<String, Object>> modelList = this.archiveClassManagerIntfsService.getModelData(nodeId);
            // String modelId = "";
            // if (modelList.size() > 0) {
            // modelId = (String) modelList.get(0).get("ID");
            // }
            /********2019-05-24 yangzengzhi 科研档案的关联按钮是否显示**********************/
            String projectFlag = request.getParameter("projectFlag");//关联按钮是否显示
            mav.addObject("projectFlag", projectFlag);

            Map<String, Object> colMap = new HashMap<String, Object>();
            colMap.put("tableId", tableId);
            colMap.put("nodeId", nodeId);
            colMap.put("sysId", sysId);
            colMap.put("flag", "1");
            colMap.put("orgId", orgId);
            colMap.put("deptId", deptId);
            //SanXiaFiles update by huangjian  start 2019 05 31
            Map<String, Object> dynamicMap = null;
            if ("2".equals(parentType)) {
                colMap.put("archiveStatus", "1");//预归档l
                dynamicMap = this.commTableManagerIntfsService.getColumnPageMapItera(colMap, addFileFieldList);
            } else {
                dynamicMap = this.commTableManagerIntfsService.getColumnPageMap(colMap);
            }

            //SanXiaFiles update by huangjian  end 2019 05 31
            dynamicMap.put("MODEL_CODE", "deptdocarrangeAddFile");
            dynamicMap.put("FORM_CODE", "addFileForm");
            String addHtml = this.billDefineDynamicService.getDynamicAddHtml(addFileFieldList, mapCode, dynamicMap);
            mav.addObject("addHtml", addHtml);

            mav.addObject("isKYDA", isKYDA);
            mav.addObject("mapCode", mapCode);
            mav.addObject("deptCols", deptCols);
            mav.addObject("addFileFieldList", addFileFieldList);
            mav.addObject("num", num);
            mav.addObject("mid", mid);
            mav.addObject("anTableId", anTableId);
            mav.addObject("sysId", sysId);
            mav.addObject("nodeId", nodeId);
            mav.addObject("tableId", tableId);
            mav.addObject("dialogId", dialogId);
            mav.addObject("dataSecret", dataSecret);
            mav.addObject("form_id", id);
            mav.addObject("mongoId", "LANTOP");
            mav.addObject("zlzt", zlzt);
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeAddFile");
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    // 存放公共数据的map
    private Map<String,Object> paramMap = new HashMap<>();

    /**
     * 跳转编辑页面方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/toEditFileJsp")
    public ModelAndView toEditFileJsp(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String id = request.getParameter("id");
        String mid = request.getParameter("mid");
        String anTableId = request.getParameter("anTableId");
        String dialogId = request.getParameter("dialogId");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String ids = request.getParameter("ids");
        String parentType = request.getParameter("parentType");//2档案类型
        String loginUserSecretLevel = SessionHelper.getLoginSysUser(request).getSecretLevel();
        Map<String, Object> pa = new HashMap<String, Object>();
        pa.put("userSecretLevel", loginUserSecretLevel);
        String dataSecret = request.getParameter("dataSecret");
        String applySave = request.getParameter("applySave");
        String zlzt = request.getParameter("zlzt");//著录状态
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("nodeId", nodeId);
    //sanxiafiles update by HJ 去掉判断 2020.1.9
        parentType = this.billDefineManagerIntfsService.getArchiveTypeByNodeIdAndTableId(orgId, sysId, nodeId, tableId);
/*

        if (parentType==null || "".equals(parentType) || "null".equals(parentType)){
            parentType = this.billDefineManagerIntfsService.getArchiveTypeByNodeIdAndTableId(orgId, sysId, nodeId, tableId);
        }
*/



        try {
            if (null != mid && !"".equals(mid)) {
                Map<String, Object> parentMap = new HashMap<String, Object>();
                parentMap.put("dataId", mid);
                param.put("ortherMap", parentMap);
            } else {
                // 判断是否有父级数据,如果没有,则添加父级密级为max,文件添加时则不进行父级数据和子级数据的密级验证
                dataSecret = "max";
            }
            Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
            param.put("languageCode", sessionLanguageCode);
            pa.put("languageCode", sessionLanguageCode);
            StringBuffer sbSql = new StringBuffer();
            StringBuffer sbAppend = new StringBuffer();
            if (ids != null && !"".equals(ids)) {
                //组件功能 修改其他数据附件
                Map<String, Object> maps = new HashMap<>();
                String[] split = ids.split(";");
                String mergeIds = "";
                for (String mergeId : split) {
                    if (!id.equals(mergeId)) {
                        List<String> fjIds = deptdocarrangeService.updateFJRecordId(mergeId, id);
                        maps.put(mergeId, fjIds);
                        mergeIds += ";" + mergeId;
                    }
                }
                if (maps != null && maps.size() > 0) {
                    mav.addObject("fjIdsMap", JSON.toJSONString(maps));
                    paramMap.put("fjIdsMap",JSON.toJSONString(maps));
                }
                mav.addObject("mergeIds", mergeIds.substring(1));
                paramMap.put("mergeIds",mergeIds.substring(1));
                paramMap.put("ids",ids);
                sbSql.append("SELECT\n" +
                        "\tS.ATTACH_NAME \n" +
                        "FROM\n" +
                        "\tSYS_ATTACHMENT S\n" +
                        "\tLEFT JOIN CBB_DOC_RELATION C ON C.ATTACHMENT_ID = S.ID \n" +
                        "WHERE\n" +
                        "\tC.RECORD_ID = '"+id+"' AND C.IF_DELETE='N' \n" +
                        "AND C.ATTRIBUTE_03 !='JKXML' ORDER BY\n" +
                        "\tC.ATTRIBUTE_11 ASC");
                List<Map<String,Object>> listData = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString());
                if(listData.size()>0){
                    for (Map<String,Object> objectMap : listData){
                        String value = objectMap.get("ATTACH_NAME")==null?"":objectMap.get("ATTACH_NAME").toString();
                        value = value.substring(0,value.lastIndexOf("."));
                        sbAppend.append(value+";");
                    }
                }
            }else {
                paramMap.put("ids",id);
            }

            // 获取id对应数据
            // List<Map<String, Object>> editList = this.billDefineManagerIntfsService.getEditOrDetailFieldsAndDataByIntfs(orgId, deptId, sysId, tableId, id, "1", param);
            //SanXiaFiels update by huangjian start
            List<Map<String, Object>> editList = null;
            if ("2".equals(parentType)) {
                param.put("archiveFlag", "1");// 预归档类型
                editList = this.billDefineManagerIntfsService.getEditOrDetailFieldsAndDataByIntfsItera(orgId, deptId, sysId, tableId, id, "1", param);
            } else {
                editList = this.billDefineManagerIntfsService.getEditOrDetailFieldsAndDataByIntfs(orgId, deptId, sysId, tableId, id, "1", param);
            }

            if(editList.size()>0){
                for (Map<String,Object> editMap : editList){
                    if(!sbAppend.toString().equals("")){
                        if(editMap.get("COL_NAME").equals("FJTM")){
                            editMap.put("COL_VALUE",sbAppend.toString()); // 组卷时，须传参数
                            break;
                        }
                    }else {
                        if(editMap.get("COL_NAME").equals("FJTM")){
                            mav.addObject("fjtmValue",editMap.get("COL_VALUE")); // 普通编辑操作时，向前台返回附件题名值
                            break;
                        }
                    }
                }

            }

            //SanXiaFiels update by huangjian end
            String deptCols = this.billDefineManagerIntfsService.getSelectDialogStringByIntfs1(orgId, deptId, sysId, tableId); // 查找选部门，选人的字段字符串
            Map<String, Map<String, String>> mapCode = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, tableId, id, "1", pa);// 获取字段通用代码数据//
            net.sf.json.JSONArray ja = net.sf.json.JSONArray.fromObject(editList);
            String jaString = ja.toString();
            mav.addObject("dataJson", jaString);

            /***** 2016/04/13增加 wangzp 页面动态显示 *****/
            // List<Map<String, Object>> modelList = this.archiveClassManagerIntfsService.getModelData(nodeId);
            // String modelId = "";
            // if (modelList.size() > 0) {
            // modelId = (String) modelList.get(0).get("ID");
            // }
            Map<String, Object> colMap = new HashMap<String, Object>();
            colMap.put("tableId", tableId);
            colMap.put("nodeId", nodeId);
            colMap.put("sysId", sysId);
            colMap.put("flag", "1");
            colMap.put("orgId", orgId);
            colMap.put("deptId", deptId);
            colMap.put("archiveStatus", "1");//著录
            //SanXiaFiels update by huangjian start
            Map<String, Object> dynamicMap = null;
            if ("2".equals(parentType)) {
                dynamicMap = this.commTableManagerIntfsService.getColumnPageMapItera(colMap, editList);
            } else {
                dynamicMap = this.commTableManagerIntfsService.getColumnPageMap(colMap);
            }
            //SanXiaFiels update by huangjian end
            dynamicMap.put("MODEL_CODE", "deptdocarrangeEditFile");
            dynamicMap.put("FORM_CODE", "editFileForm");
            /**根据dataId查询归档单位和责任者的id  qht*/
            List<Map<String, Object>> treeNodeIdList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "");
            String tableName = (String) treeNodeIdList.get(0).get("TABLE_NAME");
            List<Map<String, Object>> codeMap = this.billDefineManagerIntfsService.getCode(id, tableName);
            String archive_dept_id = codeMap.get(0).get("ARCHIVE_DEPT_ID") == null ? "" : codeMap.get(0).get("ARCHIVE_DEPT_ID").toString();
            if (!StringUtil.isEmpty(archive_dept_id) && !"null".equals(archive_dept_id)) {
                dynamicMap.put("ARCHIVE_DEPT_ID", archive_dept_id);
            } else {
                dynamicMap.put("ARCHIVE_DEPT_ID", "");
            }
            String responsible_user_id = codeMap.get(0).get("RESPONSIBLE_USER_ID") == null ? "" : codeMap.get(0).get("RESPONSIBLE_USER_ID").toString();
            if (!StringUtil.isEmpty(responsible_user_id) && !"null".equals(responsible_user_id)) {
                dynamicMap.put("RESPONSIBLE_USER_ID", responsible_user_id);
            } else {
                dynamicMap.put("RESPONSIBLE_USER_ID", "");
            }
            String editHtml = this.billDefineDynamicService.getDynamicEditHtml(editList, mapCode, dynamicMap);
            mav.addObject("editHtml", editHtml);
            mav.addObject("mapCode", mapCode);
            mav.addObject("deptCols", deptCols);
            mav.addObject("form_id", id);
            mav.addObject("mongoId", "LANTOP");
            mav.addObject("sysId", sysId);
            mav.addObject("id", id);
            mav.addObject("anTableId", anTableId);
            mav.addObject("sysId", sysId);
            mav.addObject("editList", editList);
            mav.addObject("nodeId", nodeId);
            mav.addObject("tableId", tableId);
            mav.addObject("dialogId", dialogId);
            mav.addObject("dataSecret", dataSecret);
            mav.addObject("applySave", applySave);
            mav.addObject("zlzt", zlzt);//著录状态
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeEditFile");
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 跳转详细页面方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/toDetailFileJsp")
    public ModelAndView toDetailFileJsp(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String id = request.getParameter("id");
        String dialogId = request.getParameter("dialogId");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String anTableId = request.getParameter("anTableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String openType = request.getParameter("openType");
        String userId = SessionHelper.getLoginSysUserId(request);
        String parentType = request.getParameter("parentType");//SanXiaFiles update by huangjian 2档案类型
        String reqMenuSource = request.getParameter("reqMenuSource");//SanXiaFiles update by huangjian
        mav.addObject("parentType", parentType);
        mav.addObject("reqMenuSource", reqMenuSource);
        String loginUserSecretLevel = SessionHelper.getLoginSysUser(request).getSecretLevel();
        Map<String, Object> pa = new HashMap<String, Object>();
        pa.put("userSecretLevel", loginUserSecretLevel);

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("nodeId", nodeId);
        if ("GDJH".equals(openType)) {
            List<Map<String, Object>> treeNodeIdList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(SessionHelper.getCurrentOrgId(request), SessionHelper.getCurrentDeptId(request), sysId, nodeId, "");
            if (treeNodeIdList != null && treeNodeIdList.size() > 1) {
                anTableId = (String) treeNodeIdList.get(0).get("ID");
                tableId = (String) treeNodeIdList.get(1).get("ID");
            } else {
                tableId = (String) treeNodeIdList.get(0).get("ID");
            }
        }
        try {
            Map<String, Object> listParam = new HashMap<String, Object>();
            Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
            params.put("languageCode", sessionLanguageCode);
            pa.put("languageCode", sessionLanguageCode);
            // 获取id对应数据
            List<Map<String, Object>> editList = null;
            if ("2".equals(parentType)) {
                params.put("archiveFlag", "1");// 预归档类型
                editList = this.billDefineManagerIntfsService.getEditOrDetailFieldsAndDataByIntfsItera(orgId, deptId, sysId, tableId, id, "3", params);
            } else {
                editList = this.billDefineManagerIntfsService.getEditOrDetailFieldsAndDataByIntfs(orgId, deptId, sysId, tableId, id, "3", params);
            }

            List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, tableId, "1", "100", " AND ID = '" + id + "'", listParam);
            String isFlag = "false";
            if (list.size() > 0) {
                Map<String, Object> map = list.get(0);
                Object obj = map.get("PARENT_ID");
                if (null != obj && !"".equals(obj)) {
                    List<Map<String, Object>> anList = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, anTableId, "1", "100", " AND ID = '" + obj + "'", listParam);
                    if (anList.size() > 0) {
                        isFlag = "true";
                        Map<String, Object> anMap = anList.get(0);
                        mav.addObject("archive_code", anMap.get("AJH"));
                    }
                }
            }
            mav.addObject("isFlag", isFlag);
            LantopArchiveClass lac = this.archiveclassmanagerService.getArchiveclassmanagerById(nodeId);
            Map<String, Object> map = this.archiveclassmanagerService.getPathNameByPath(lac.getArchiveClassNodePath());
            String path = "";
            if (null != map.get("ARCHIVE_CLASS_PATH_NAME")) {
                path = map.get("ARCHIVE_CLASS_PATH_NAME").toString();
            }
            mav.addObject("archive_path", path);

            String deptCols = this.billDefineManagerIntfsService.getSelectDialogStringByIntfs(orgId, deptId, sysId, tableId); // 查找选部门，选人的字段字符串
            Map<String, Map<String, String>> mapCode = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, tableId, id, "3", pa);// 获取字段通用代码数据//
            /***** 2016/04/13增加 wangzp 页面动态显示 *****/
            // List<Map<String, Object>> modelList = this.archiveClassManagerIntfsService.getModelData(nodeId);
            // String modelId = "";
            // if (modelList.size() > 0) {
            // modelId = (String) modelList.get(0).get("ID");
            // }
            Map<String, Object> colMap = new HashMap<String, Object>();
            colMap.put("tableId", tableId);
            colMap.put("nodeId", nodeId);
            colMap.put("sysId", sysId);
            colMap.put("flag", "3");
            colMap.put("orgId", orgId);
            colMap.put("deptId", deptId);
            Map<String, Object> dynamicMap = null;
            //SanXiaFiles update by huangjian start
            if ("2".equals(parentType)) {
                //判断来源 3馆藏，2著录整理  1整理归档
                colMap.put("archiveStatus", reqMenuSource);//3馆藏，2著录整理  1整理归档
                dynamicMap = this.commTableManagerIntfsService.getColumnPageMapItera(colMap, editList);
            } else {
                dynamicMap = this.commTableManagerIntfsService.getColumnPageMap(colMap);
            }
            //SanXiaFiles update by huangjian end
            dynamicMap.put("MODEL_CODE", "deptdocarrangeDetailFile");
            dynamicMap.put("FORM_CODE", "detailFileForm");
            String detailHtml = this.billDefineDynamicService.getDynamicDetailHtml(editList, mapCode, dynamicMap);
            mav.addObject("detailHtml", detailHtml);

            // 参数
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("sysId", sysId);
            param.put("dataId", id);
            param.put("nodeId", nodeId);
            param.put("deptId", deptId);
            param.put("orgId", orgId);
            // 获取相关档案
            List<Map<String, Object>> relList = this.archiverelatesetIntfsService.getRelTableComList(param);
            for (int i = 0; i < relList.size(); i++) {
                Map<String, Object> relMap = relList.get(i);
                String wjh = (String) relMap.get("WJH");
                wjh = null == wjh || "null".equals(wjh) ? "【空】" : wjh;
                String tm = (String) relMap.get("TM");
                tm = null == tm || "null".equals(tm) ? "【空】" : tm;

                String val = wjh + "|" + tm;
                String title = val;
                if (null != val && val.length() > 15) {
                    val = val.substring(0, 15) + "...";
                }
                relMap.put("ALLVAL", title);
                relMap.put("VAL", val);
            }
            mav.addObject("relList", relList);
            // 查找字段生成方式为通用代码的集合
            mav.addObject("mapCode", mapCode);
            mav.addObject("deptCols", deptCols);
            mav.addObject("form_id", id);
            mav.addObject("mongoId", "LANTOP");
            mav.addObject("sysId", sysId);
            mav.addObject("orgId", orgId);
            mav.addObject("deptId", deptId);
            mav.addObject("userId", userId);
            mav.addObject("id", id);
            mav.addObject("editList", editList);
            mav.addObject("nodeId", nodeId);
            mav.addObject("tableId", tableId);
            mav.addObject("dialogId", dialogId);
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeDetailFile");
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 更新方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/updateFileDatas")
    public ModelAndView updateFileDatas(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        paramMap.clear();
        Map<String, Object> map = JsonUtils.newInstance().Json2Bean2Form(request.getParameter("datas"), HashMap.class);
        String id = request.getParameter("id");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String anTableId = request.getParameter("anTableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String fjtmValue = request.getParameter("fjtm"); // 待更新的附件题名字段
        // SanXiaFiles create by zhaoxiaolong 如果须要更新的附件题名字段值不为空，证明用户删除过对应附件，须要更新对应附件名称
        if(map==null&&fjtmValue!=null){
            map = new HashMap<>();
            map.put("FJTM",fjtmValue);
        }
        map.put("ID", id);
        //zcl 标识更新类型  整理归档编辑  修改更新时间  修改bug->比较档案信息的创建时间和最后更新时间，如果最后更新时间大于创建时间就认为该党案信息已经进行过编辑，未编辑的档案信息加粗或变红，编辑的档案信息后变为正常字体
        String type = request.getParameter("type");
        if ("edit".equals(type)) {
            map.put("LAST_UPDATE_DATE", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        }
        Map<String, Object> listParam = new HashMap<String, Object>();
        try {
            Map<String, Object> getIndex = new HashMap<String, Object>();
            getIndex.put("sysId", sysId);
            getIndex.put("orgId", orgId);
            getIndex.put("deptId", deptId);
            getIndex.put("tableId", tableId);
            getIndex.put("dataId", id);
            getIndex.put("mapObj", map);
            String colLabels = "";// 唯一索引字段
            boolean isExist = false;
            // 获取索引信息
            List<Map<String, Object>> tableIndex = commTableManagerIntfsService.getTableIndexByParam(getIndex);
            if (null != tableIndex) {
                for (Map<String, Object> m : tableIndex) {
                    isExist = ((Boolean) m.get("isExist")).booleanValue();
                    colLabels = (String) m.get("message");
                }
            }
            if (isExist == false) {
                String appId = this.sysApplicationAPI.getCurrentAppId();
                String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
                String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
                String parentId = "";
                // 文件原数据
                List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, tableId, "1", "100", " AND ID = '" + id + "'", listParam);
                if (list.size() > 0) {
                    Map<String, Object> resultMap = list.get(0);
                    parentId = (String) resultMap.get("PARENT_ID");
                }

                Map<String, Object> param = new HashMap<String, Object>();
                param.put("ajDataId", parentId);
                param.put("modleName", modleName);
                this.billDefineManagerIntfsService.updateRecordByDataIdWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, tableId, map, id, param);
                /** SanXiaFiles create by zhaoxiaolong 更改新起止日期 start **/
                this.billDefineManagerIntfsService.UpdateQzrqByAnIdAndAnTableId(parentId,anTableId,null);
                /** SanXiaFiles create by zhaoxiaolong 更改新起止日期 end **/
                mav.addObject("ID", id);
                mav.addObject("flag", OpResult.success.ordinal());
            } else {
                mav.addObject("colLabels", colLabels);
                mav.addObject("flag", OpResult.failure.ordinal());
            }
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 文件著录方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/saveFileDatas")
    public ModelAndView saveFileDatas(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        Map<String, Object> map = JsonUtils.newInstance().Json2Bean2Form(request.getParameter("datas"), HashMap.class);
        String mid = request.getParameter("mid");
        // 需要插入的卷内序号
        String num = request.getParameter("num");
        String anTableId = request.getParameter("anTableId");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String zlzt = request.getParameter("zlzt");
        String loginUserId = SessionHelper.getLoginSysUserId(request);
        String loginIp = SessionHelper.getClientIp(request);
        map.put("ORG_ID", orgId);
        map.put("DEPT_ID", deptId);
        map.put("SYS_ID", sysId);
        map.put("NODE_ID", nodeId);
        map.put("ARCHIVE_STATUS", "0");
        map.put("ARCHIVE_FLOW_STATUS", "1");
        map.put("ARCHIVE_SHARE_STATUS", "2");
        map.put("ZLZT", zlzt);
        Map<String, Object> listParam = new HashMap<String, Object>();
        try {
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            if (null != num && !"".equals(num)) {
                // this.updateFileDataByAnDataId(orgId, deptId, sysId, tableId, anTableId, nodeId, mid, num, resultId, menuName);
                // 处理卷内序号
                Map<String, Object> parameter = new HashMap<String, Object>();
                parameter.put("orgId", orgId);
                parameter.put("insertObjNum", num);
                parameter.put("deptId", deptId);
                parameter.put("sysId", sysId);
                parameter.put("type", "insert");
                parameter.put("parentId", mid);
                parameter.put("tableId", tableId);
                parameter.put("modleName", modleName);
                this.billDefineManagerIntfsService.saveOtherArchiveInNumByIntfsByParam(parameter);
            }
            String shareStatus = "";
            if (null != mid && !"".equals(mid)) {
                map.put("PARENT_ID", mid);
                if (null == num || "".equals(num)) {
                    // if (!map.containsKey("ARCHIVE_IN_NUM") || null == map.get("ARCHIVE_IN_NUM") || "".equals(map.get("ARCHIVE_IN_NUM"))) {
                    String sql = " AND PARENT_ID = '" + mid + "'";
                    Object obj = this.billDefineManagerIntfsService.getOperationTableColDataByIntfs(tableId, sql, "ARCHIVE_IN_NUM", orgId, deptId, sysId, "MAX");
                    if (null != obj) {
                        num = obj.toString();
                        int newNum = Integer.valueOf(num) + 1;
                        num = newNum + "";
                    } else {
                        num = "1";
                    }
                    // }
                }
                // 判断案卷数据是否已共享
                /*List<Map<String, Object>> anList = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, anTableId, "1", "100", " AND ID = '" + mid + "'", listParam);
                if (anList.size() > 0) {
                    Map<String, Object> anMap = anList.get(0);
                    shareStatus = (String) anMap.get("ARCHIVE_SHARE_STATUS_CODE");
                    map.put("ARCHIVE_SHARE_STATUS", shareStatus);
                }*/
            }
            if (null != num && !"".equals(num)) {
                map.put("ARCHIVE_IN_NUM", num);
            }
            map.put("modleName", modleName);
            Map<String, Object> getIndex = new HashMap<String, Object>();
            getIndex.put("sysId", sysId);
            getIndex.put("orgId", orgId);
            getIndex.put("deptId", deptId);
            getIndex.put("nodeId", nodeId);
            getIndex.put("tableId", tableId);
            getIndex.put("mapObj", map);
            getIndex.put("loginUserId", loginUserId);
            getIndex.put("loginIp", loginIp);
            // 获取索引信息
            List<Map<String, Object>> tableIndex = commTableManagerIntfsService.getTableIndexByParam(getIndex);
            boolean isExist = false;
            String colLabels = "";
            if (null != tableIndex) {
                for (Map<String, Object> m : tableIndex) {
                    isExist = ((Boolean) m.get("isExist")).booleanValue();
                    colLabels = (String) m.get("message");
                }
            }
            if (isExist == false) {
                String resultId = this.billDefineManagerIntfsService.insertRecordByIntfs(orgId, deptId, sysId, nodeId, tableId, map, loginUserId, loginIp);
                if (null != mid && !"".equals(mid)) {
                    if (null != shareStatus && !"".equals(shareStatus) && !"0".equals(shareStatus)) {
                        List<LantopFileShare> lfsList = this.deptdocarrangeService.getShareListByRecordId(mid);
                        // 案卷目录标签页物理表信息
                        List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "2");
                        Map<String, Object> fileMap = fileList.get(0);
                        String tableName = fileMap.get("TABLE_NAME").toString();
                        String tableTitle = fileMap.get("TABLE_TITLE").toString();
                        List<Map<String, Object>> list = this.archiveClassManagerIntfsService.getArchiveClassListInfoByIntfs(nodeId);
                        String nodePath = "";
                        if (list.size() > 0) {
                            Map<String, Object> nodeMap = list.get(0);
                            nodePath = nodeMap.get("ARCHIVE_CLASS_NODE_PATH").toString();
                        }
                        for (int i = 0; i < lfsList.size(); i++) {
                            LantopFileShare lfs = lfsList.get(i);
                            String shareUserId = lfs.getShareUserId();
                            String shareDeptId = lfs.getShareDeptId();
                            LantopFileShare newLFS = new LantopFileShare();
                            newLFS.setArchiveTableId(tableId);
                            newLFS.setArchiveTableName(tableName);
                            newLFS.setArchiveTableTitle(tableTitle);
                            newLFS.setArchiveClassNodePath(nodePath);
                            newLFS.setArchiveClassId(nodeId);
                            newLFS.setOrgId(orgId);
                            newLFS.setDeptId(deptId);
                            newLFS.setSysId(sysId);
                            if (null != shareUserId && !"".equals(shareUserId)) {
                                newLFS.setShareUserId(shareUserId);
                            } else if (null != shareDeptId && !"".equals(shareDeptId)) {
                                newLFS.setShareDeptId(shareDeptId);
                            }
                            newLFS.setRecordId(resultId);
                            this.deptdocarrangeService.saveFileShare(newLFS);
                        }
                    }
                    billDefineManagerIntfsService.UpdateQzrqByAnIdAndAnTableId(mid,anTableId,null);
                }
                //this.billDefineManagerIntfsService.UpdateJsByAnIdAndAnTableId(mid,anTableId, tableId, orgId, deptId, sysId);
                mav.addObject("ID", resultId);
                mav.addObject("flag", OpResult.success.ordinal());
            } else {
                mav.addObject("colLabels", colLabels);
                mav.addObject("flag", OpResult.failure.ordinal());
            }
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 组卷时循环更新卷内序号
     *
     * @throws Exception void
     * @author 钟一华
     */
    public void updateFileDataByAnDataId(String orgId, String deptId, String sysId, String tableId, String
            anTableId, String nodeId, String parentId, String num, String selfId, String modleName) throws Exception {
        Map<String, Object> listParam = new HashMap<String, Object>();
        String sql = " AND PARENT_ID = '" + parentId + "' AND ID != '" + selfId + "' AND ARCHIVE_IN_NUM >= '" + num + "'";
        List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, tableId, "1", "100", sql, listParam);
        int newNumber = Integer.valueOf(num);
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("ajDataId", parentId);
        param.put("modleName", modleName);
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> map = list.get(i);
            Map<String, Object> updateMap = new HashMap<String, Object>();
            newNumber++;
            updateMap.put("ARCHIVE_IN_NUM", newNumber);
            this.billDefineManagerIntfsService.updateRecordByDataIdWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, tableId, updateMap, map.get("ID").toString(), param);
        }
    }


    /**
     * SanXiaFiles create by zhaoxiaolong 查询表是否存在此字段
     * @param columnName
     * @param tableId
     * @return
     */
    private boolean isExistColumn(String columnName,String tableId){
        StringBuffer sbSql = new StringBuffer();
        sbSql.append("SELECT\n" +
                "\tCOUNT( 1 ) COUNT \n" +
                "FROM\n" +
                "\tUSER_TAB_COLUMNS \n" +
                "WHERE\n" +
                "\tTABLE_NAME = ( SELECT TABLE_NAME FROM CBB_TABLES WHERE ID = '"+tableId+"' ) \n" +
                "\tAND COLUMN_NAME = '"+columnName+"' ");
        List<Map<String,Object>> countlist = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString());
        if(countlist!=null&&countlist.size()>0){
            int count = Integer.valueOf(countlist.get(0).get("COUNT").toString());
            if(count>0){
                return true;
            }else {
                return false;
            }
        }else {
            return false;
        }
    }


    /**
     * SanXiaFiles create by zhaoxiaolong 根据当前数据节点ID查询对应父级节点是否存在
     * @param nodeId
     * @param archiveClassNodeName
     * @return
     */
    private boolean getParentNodeDataByNodeNameAndNodeId(String nodeId,String archiveClassNodeName){
        StringBuffer sbSql = new StringBuffer();
        sbSql.append("\n" +
                "SELECT\n" +
                "\tCOUNT( 1 ) COUNT \n" +
                "FROM\n" +
                "\t( SELECT ARCHIVE_CLASS_NODE_NAME FROM LANTOP_ARCHIVE_CLASS START WITH ID = '"+nodeId+"' CONNECT BY PRIOR PARENT_ID = ID ) \n" +
                "WHERE\n" +
                "\tARCHIVE_CLASS_NODE_NAME = '"+archiveClassNodeName+"'");
        List<Map<String,Object>> countlist = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString());
        if(countlist!=null&&countlist.size()>0){
            int count = Integer.valueOf(countlist.get(0).get("COUNT").toString());
            if(count>0){
                return true;
            }else {
                return false;
            }
        }else {
            return false;
        }
    }


    /**
     * 获得文件目录列表数据集合
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getAllFileTableList")
    public ModelAndView getAllFileTableList(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        // 查询类型（查询入口）
        String searchFlag = request.getParameter("searchFlag");
        // 查询区域结果中查询flag
        String resultSearchFlag = request.getParameter("resultSearchFlag");
        // 高级查询结果中查询flag
        String highSelectResultSearchFlag = request.getParameter("highSelectResultSearchFlag");
        String createdNum = request.getParameter("createdNum");
        String orderCols = request.getParameter("orderCols");
        String isParent = request.getParameter("isParent");
        String json = request.getParameter("param");
        String share = request.getParameter("share");
        String status = "0";//request.getParameter("status");
        String tableId = request.getParameter("tableId");
        String nodeId = request.getParameter("nodeId");
        String mid = request.getParameter("mid");
        String showFlag = request.getParameter("showFlag");
        String recycle = request.getParameter("recycle");
        boolean showFlagCheck = Boolean.valueOf(showFlag);
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String userId = SessionHelper.getLoginSysUserId(request);
        String sysId = request.getParameter("sysId");
        String page = request.getParameter("page");
        String rows = request.getParameter("rows");
        String pageNo = request.getParameter("pageNo");
        String pageSize = request.getParameter("pSize");// 取得一页显示的数量
        String flowStatus = request.getParameter("flowStatus"); // 流程状态
        String archivechType = request.getParameter("archivechType");//2档案类型
        String zlzt = request.getParameter("zlzt");//著录状态 1：待整理 2：整理中
        String appId = SessionHelper.getApplicationId();

        String queryDimension = request.getParameter("queryDimension"); //拼接SQL查询条件维度过滤 SanXiaFiles create by zhaoxiaolong

        // SanXiaFiles create by zhaoxiaolong 查询当前表是否存在归档单位（ARCHIVE_DEPT）和项目负责人（XMFZR）字段
        boolean isExistArchiveDept = false; // 是否存在归档部门字段
        boolean isExistxmfzr = false; // 是否存在项目负责人字段
        boolean isExistNodeName = false; // 当前数据节点的父类是否是技术类
        boolean fileTabFlag = false; // 是否为文件级
        String loginName = SessionHelper.getLoginName(request);
        loginName = loginName.toUpperCase();
        SysUser sysUser = SessionHelper.getLoginSysUser(request);
        String userName = sysUser.getName();
        StringBuffer searchSbSql = new StringBuffer(); // 根据维度进行拼接SQL
        if(tableId!=null&&!tableId.equals("")){
            String archiveDeptName = "ARCHIVE_DEPT"; // 归档部门字段名称
            String xmfzrName = "XMFZR"; // 项目负责人字段名称
            isExistArchiveDept = isExistColumn(archiveDeptName,tableId);
            isExistxmfzr = isExistColumn(xmfzrName,tableId);
        }
        if (nodeId!=null&&nodeId!=""){
            isExistNodeName = getParentNodeDataByNodeNameAndNodeId(nodeId,"技术类"); // 查询当前数据节点的父级是否有技术类
        }
        // SanXiaFiles create by zhaoxiaolong 是否为文件级表名
        if (tableId!=null&&!"".equals(tableId)&&!"null".equals(tableId)){
            StringBuffer sbTabSql = new StringBuffer();
            sbTabSql.append("SELECT TABLE_NAME FROM CBB_TABLES WHERE ID='"+tableId+"'");
            List<Map<String,Object>> tabDataList = this.jdbcAvicit.getJdbcTemplate().queryForList(sbTabSql.toString());
            if(tabDataList!=null&&tabDataList.size()>0){
                String tabName = tabDataList.get(0).get("TABLE_NAME").toString();
                if (tabName.indexOf("WJJ")!=-1||tabName.indexOf("WJ")!=-1){
                    fileTabFlag = true;
                }
            }
        }
        if (queryDimension!=null&&queryDimension!=""){
            if(isExistArchiveDept||isExistxmfzr){
                if(queryDimension.equals("1")){  // 兼职档案管理员根据归档部门是当前部门的，并且如果该数据节点是技术类下的，需要加上项目负责人是当前登录用户的过滤
                    String currentDeptName = SessionHelper.getCurrentDeptName(request); // 当前登录部门名称
                    if (isExistArchiveDept){
                        searchSbSql.append(" AND ( ARCHIVE_DEPT = '"+currentDeptName+"' OR   CREATED_BY='"+userId+"' OR DEPT_ID='"+deptId+"' ) ");
                    }else {
                        mav.addObject("total", 0);
                        mav.addObject("rows", new ArrayList<>());
                        return mav;
                    }
                    if (isExistNodeName){ // 父级是技术类需要增加项目负责人查询SQL
                        if(!fileTabFlag){ // 案卷需要判断项目负责人是否存在
                            if (isExistxmfzr){
                                if(searchSbSql!=null&&searchSbSql.toString()!=""){
                                    searchSbSql = new StringBuffer();
                                    searchSbSql.append(" AND ( CREATED_BY='"+userId+"' OR ARCHIVE_DEPT = '"+currentDeptName+"' OR DEPT_ID='"+deptId+"' ");
                                    searchSbSql.append(" OR ( UPPER(XMFZR) = '"+userName+"("+loginName+")') ) ");
                                }else {
                                    searchSbSql.append(" AND ( ( UPPER(XMFZR) = '"+userName+"("+loginName+")')  OR   CREATED_BY='"+userId+"' ) ");
                                }
                            }else {
                                // 如果没有项目负责人字段，查询创建人是自己的
                                searchSbSql.append(" AND  CREATED_BY='"+userId+"'  ");
                            }
                        }
                    }
                }else if (queryDimension.equals("2")){
                    if (fileTabFlag){ // 文件级，不需要校验项目负责人
                        searchSbSql.append(" AND  CREATED_BY='"+userId+"'  ");
                    }else {
                        if (isExistNodeName){ // 父级是技术类需要增加项目负责人查询SQL
                            if (isExistxmfzr){
                                searchSbSql.append(" AND ( ( UPPER(XMFZR) = '"+userName+"("+loginName+")')  OR   CREATED_BY='"+userId+"'  ) ");
                            }else {
                                // 如果没有项目负责人字段，查询创建人是自己的
                                searchSbSql.append(" AND  CREATED_BY='"+userId+"'  ");
                            }
                        }else {
                            // 文件级，不需要校验项目负责人
                            searchSbSql.append(" AND  CREATED_BY='"+userId+"'  ");
                        }
                    }
                }
            }else {
                mav.addObject("total", 0);
                mav.addObject("rows", new ArrayList<>());
                return mav;
            }
        }
        if (null == pageNo) {
            if (page!=null && !"".equals(page)){
                pageNo = page;
            }else {
                pageNo = "1";
            }
        }
        if (null == pageSize) {
            if(rows!=null&&!"".equals(rows)){
                pageSize=rows;
            }else {
                pageSize = "100";
            }
        }

        String onlyDeptSee = "0"; // 仅部门可见 0 否 1 是
        List<Map<String, Object>> listNode = archiveclassmanagerService.getArchiveClassTreeNodeByNodeId(nodeId);
        if (listNode.size() > 0) {
            Map<String, Object> map = listNode.get(0);
            Object attribute01 = map.get("ATTRIBUTE_01");
            if (null != attribute01 && !attribute01.equals("")) {
                onlyDeptSee = attribute01.toString();
            }
        }

        // String appId = SessionHelper.getApplicationId();
        // 高级查询sql语句
        String whereSql = request.getParameter("whereSql");
        // 高级查询带表名语句
        String highSelectSql = request.getParameter("highSelectSql");
        // 打印查询sql语句
        StringBuffer printQuerySql = new StringBuffer();
        // 需要查询的表名
        String printTableName = "";
        List<Map<String, Object>> tableColumnList = this.commTableManagerIntfsService.getCbbTableAndColumnsByTabIdByIntfs(tableId);
        if (tableColumnList.size() > 0) {
            printTableName = (String) tableColumnList.get(0).get("TABLE_NAME");
        }
        Map<String, Object> listParam = new LinkedHashMap<String, Object>();
        Map<String, String> orderMap = new LinkedHashMap<String, String>();
        JSONArray orderColsJSONArray = JSON.parseArray(orderCols);
        int o = 0;//判断是否进入自定义排序
        Map<String, String> orderColsMapString = new HashMap<String, String>();
        if (null != orderCols && !orderCols.equals("") && !orderCols.equals("null")) {
            for (int i = 0; i < orderColsJSONArray.size(); i++) {
                String orderColsJSONString = orderColsJSONArray.get(i).toString();
                orderColsMapString = JsonUtils.newInstance().Json2Bean2Form(orderColsJSONString, Map.class);
                String name = orderColsMapString.get("COL_NAME");
                String sort = orderColsMapString.get("SORT_CODE");
                if (null != sort && !sort.equals("") && !sort.equals("null")) {
                    if (sort.equals("A")) {
                        sort = "ASC";
                        o++;
                    } else if (sort.equals("D")) {
                        sort = "DESC";
                        o++;
                    }
                }
                orderMap.put(name, sort);
            }
        }
        if(o == 0){
        	//未进自定义排序，那么给默认排序字段
        	if("1".equals(zlzt)){
                orderMap.put("CREATION_DATE", "ASC");
                orderMap.put("WSCLLX", "ASC");
                orderMap.put("BWBH", "ASC");
                orderMap.put("WJH", "ASC");
                orderMap.put("RQ", "ASC");
        	}else if("2".equals(zlzt)){
                orderMap.put("ZLH", "ASC");
        	}else{
        		//案卷-文件级
                orderMap.put("ARCHIVE_IN_NUM", "ASC");
        	}
        }
        listParam.put("searchOrder", orderMap);
        //做一个自定义排序标识
        listParam.put("customSorting", true);
        // Map<String, Object> searchMap = new HashMap<String, Object>();
        // if (null != json && !"".equals(json)) {
        // searchMap = JsonUtils.newInstance().Json2Bean2DataGrid(json, Map.class);
        // }
        // String checkNodes = (String) searchMap.get("checkNodes");
        // searchMap.remove("checkNodes");
        // searchMap.remove("resultSearch");
        // if (null == checkNodes) {
        // checkNodes = request.getParameter("checkAllNode");
        // }
        StringBuffer sb = new StringBuffer();
        if (null == isParent || "".equals(isParent)) {
            // if ("on".equals(checkNodes)) {
            // 由于跨节点检索暂不进行权限控制，那么去掉node_id条件过滤
            /*
             * String pId = this.deptdocarrangeService.getParentNodeIdById(nodeId); List<Map<String, Object>> nodeList =
             * this.deptdocarrangeService.getSelectNodesByStartNodeId(pId); String sqlIds = ""; for (int i = 0; i < nodeList.size(); i++) { Map<String, Object> nodeMap =
             * nodeList.get(i); sqlIds += "'" + nodeMap.get("ID") + "',"; } sqlIds = sqlIds.substring(0, sqlIds.length() - 1); sb.append(" AND NODE_ID IN (" + sqlIds + ")");
             * printQuerySql.append(" AND " + printTableName + ".NODE_ID IN (" + sqlIds + ")");
             */
            // } else {
            sb.append(" AND NODE_ID = '" + nodeId + "' ");
            sb.append(searchSbSql.toString());
            // printQuerySql.append(" AND " + printTableName + ".NODE_ID = '" + nodeId + "'");
            // }
        } else {
            sb.append(" AND NODE_ID IN (");
            // printQuerySql.append(" AND " + printTableName + ".NODE_ID IN (");
            List<Map<String, Object>> nodeList = this.deptdocarrangeService.getChildNodeIdByParentId(isParent);
            String ids = "";
            for (int i = 0; i < nodeList.size(); i++) {
                Map<String, Object> map = nodeList.get(i);
                ids += "'" + map.get("ID") + "'";
                if (i != nodeList.size() - 1) {
                    ids += ",";
                }
            }
            sb.append(ids + ")");
        }
        StringBuffer searchSb = new StringBuffer();
        // 定义查询区域带表名查询条件
        StringBuffer searchTableSb = new StringBuffer();
        String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
        SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
        String orgCode = so.getOrgCode();
        Map<String, Object> searchParam = new HashMap<String, Object>();
        searchParam.put("currentUserId", userId);
        searchParam.put("currentDeptId", deptId);
        searchParam.put("currentOrgCode", orgCode);
        searchParam.put("nodeId", nodeId);
        Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
        searchParam.put("languageCode", sessionLanguageCode);
        // 日志查询条件
        String searchString = "";
        // 文件动态查询字段集合
        //SanXiaFiles update by hunagjian start
        List<Map<String, Object>> fileSearchList = null;
        if ("2".equals(archivechType)) {//2档案类型
            //SanXiaFiles update by huangjian start
            searchParam.put("archiveFlag", "1");//3馆藏，2著录整理  1整理归档
            fileSearchList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfsItera(orgId, deptId, sysId, tableId, "4", "", searchParam);
        } else {
            fileSearchList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, tableId, "4", "", searchParam);
        }
        //SanXiaFiles update by hunagjian end
        if (fileSearchList.size() > 0 && null != json && !"".equals(json) && !json.equals("{}")) {
            json = URLDecoder.decode(URLDecoder.decode(json, "utf-8"), "utf-8");
            sb.append(" AND (");
            printQuerySql.append(" AND (");
            for (int i = 0; i < fileSearchList.size(); i++) {
                Map<String, Object> fileSearchMap = fileSearchList.get(i);
                String colLabel = (String) fileSearchMap.get("COL_LABEL");
                String colName = (String) fileSearchMap.get("COL_NAME");
                String colType = (String) fileSearchMap.get("COL_TYPE");
                if ("date".equals(colType)) {
                    searchString += colLabel + " 等于 " + json;
                    sb.append("to_char("+colName + ", 'yyyy-MM-dd') like '%" + json + "%'");
                    printQuerySql.append(colName + " = TO_DATE('" + json + "', 'yyyy-MM-dd')");
                } else if ("integer".equals(colType) || "float".equals(colType)) {
                    if(!NumberUtils.isNumber(json)){
                        continue;
                    }
                    searchString += colLabel + " 等于 " + json;
                    sb.append(colName + " = " + json );
                    printQuerySql.append(colName + " = '" + json + "'");
                } else {
                    searchString += colLabel + " 包含 " + json;
                    sb.append(colName + " LIKE '%" + json + "%'");
                    printQuerySql.append(colName + " LIKE '%" + json + "%'");
                }
                if (i != fileSearchList.size() - 1) {
                    searchString += " 或者 ";
                    sb.append(" OR ");
                    printQuerySql.append(" OR ");
                }
            }
            sb.append(" ) ");
            printQuerySql.append(" ) ");
        }

        if (null != mid && !"".equals(mid)) {
            sb.append(" and PARENT_ID = '" + mid + "'");
            printQuerySql.append(" and " + printTableName + ".PARENT_ID = '" + mid + "'");
        } else {
            if (showFlagCheck == false) {
                sb.append(" and (PARENT_ID = '' OR DECODE(PARENT_ID,NULL,1)=1)");
                printQuerySql.append(" and (" + printTableName + ".PARENT_ID = '' OR " + printTableName + ".PARENT_ID IS NULL)");
            }
        }

        if (onlyDeptSee.equals("1")) {
            sb.append(" AND DEPT_ID = '" + deptId + "'");
            printQuerySql.append(" AND " + printTableName + ".DEPT_ID = '" + deptId + "'");
        }

        if ("recycleFile".equals(recycle)) {
            sb.append(" AND ARCHIVE_STATUS = '2'");
            printQuerySql.append(" AND " + printTableName + ".ARCHIVE_STATUS = '2'");
        } else {
            if (null != status && !"".equals(status)) {
                if ("2".equals(status)) {
                    sb.append(" AND ARCHIVE_STATUS = '3'");
                    printQuerySql.append(" AND " + printTableName + ".ARCHIVE_STATUS = '3'");
                } else if ("1".equals(status)) {
                    sb.append(" AND (ARCHIVE_STATUS = '1' OR ARCHIVE_STATUS IS NULL OR ARCHIVE_STATUS = '')");
                    printQuerySql.append(" AND (" + printTableName + ".ARCHIVE_STATUS = '1' OR " + printTableName + ".ARCHIVE_STATUS IS NULL OR " + printTableName + ".ARCHIVE_STATUS = '')");
                } else if ("0".equals(status)) {
                    sb.append(" AND (ARCHIVE_STATUS = '0')");
                    printQuerySql.append(" AND (" + printTableName + ".ARCHIVE_STATUS = '0')");
                } else {
                    sb.append(" AND (ARCHIVE_STATUS = '1' OR ARCHIVE_STATUS = '3' OR ARCHIVE_STATUS = '4' OR ARCHIVE_STATUS IS NULL OR ARCHIVE_STATUS = '')");
                    printQuerySql.append(" AND (" + printTableName + ".ARCHIVE_STATUS = '1' OR " + printTableName + ".ARCHIVE_STATUS = '3' OR " + printTableName + ".ARCHIVE_STATUS = '4' OR " + printTableName + ".ARCHIVE_STATUS IS NULL OR " + printTableName
                            + ".ARCHIVE_STATUS = '')");
                }
            } else {
                sb.append(" AND (ARCHIVE_STATUS = '1' OR ARCHIVE_STATUS = '3' OR ARCHIVE_STATUS = '4' OR ARCHIVE_STATUS IS NULL OR ARCHIVE_STATUS = '')");
                printQuerySql.append(" AND (" + printTableName + ".ARCHIVE_STATUS = '1' OR " + printTableName + ".ARCHIVE_STATUS = '3' OR " + printTableName + ".ARCHIVE_STATUS = '4' OR " + printTableName + ".ARCHIVE_STATUS IS NULL OR " + printTableName + ".ARCHIVE_STATUS = '')");
            }
        }
        // 流程状态字段过滤
        if (null != flowStatus && !"".equals(flowStatus)) {
            if (!"0".equals(flowStatus)) {
                if ("1".equals(flowStatus)) {
                    sb.append(" AND (ARCHIVE_FLOW_STATUS = '1' OR ARCHIVE_FLOW_STATUS = '2' OR ARCHIVE_FLOW_STATUS = '' OR ARCHIVE_FLOW_STATUS IS NULL)");
                    printQuerySql.append(" AND (" + printTableName + ".ARCHIVE_FLOW_STATUS = '" + flowStatus + "' OR " + printTableName + ".ARCHIVE_FLOW_STATUS = '' OR " + printTableName + ".ARCHIVE_FLOW_STATUS IS NULL  OR " + printTableName + ".ARCHIVE_FLOW_STATUS = '2')");
                } else {
                    sb.append(" AND ARCHIVE_FLOW_STATUS = '" + flowStatus + "'");
                    printQuerySql.append(" AND " + printTableName + ".ARCHIVE_FLOW_STATUS = '" + flowStatus + "'");
                }
            }
        } else {
            sb.append(" AND (ARCHIVE_FLOW_STATUS = '1' OR ARCHIVE_FLOW_STATUS = '2' OR ARCHIVE_FLOW_STATUS = '' OR ARCHIVE_FLOW_STATUS IS NULL)");
            printQuerySql.append(" AND (" + printTableName + ".ARCHIVE_FLOW_STATUS = '1' OR " + printTableName + ".ARCHIVE_FLOW_STATUS = '' OR " + printTableName + ".ARCHIVE_FLOW_STATUS IS NULL OR " + printTableName + ".ARCHIVE_FLOW_STATUS='2')");
        }
        if (null != share && !"".equals(share)) {
            if ("yes".equals(share)) {
                if ("".equals(isParent)) {
                    List<LantopFileShare> lfsList = this.deptdocarrangeService.getShareDataIdsByTableIdAndDeptId(nodeId, tableId, deptId, userId);
                    String ids = "";
                    for (int i = 0; i < lfsList.size(); i++) {
                        LantopFileShare lfs = lfsList.get(i);
                        ids += "'" + lfs.getRecordId() + "',";
                    }
                    if (ids.length() > 1) {
                        ids = ids.substring(0, ids.length() - 1);
                    }
                    if (ids.length() > 1) {
                        sb.append(" AND ID IN (" + ids + ")");
                        printQuerySql.append(" AND " + printTableName + ".ID IN (" + ids + ")");
                    } else {
                        sb.append(" AND ID IS NULL");
                        printQuerySql.append(" AND " + printTableName + ".ID IS NULL");
                    }
                } else {
                    List<Map<String, Object>> nodeList = this.deptdocarrangeService.getChildNodeIdByParentId(isParent);
                    String parent = "";
                    for (int i = 0; i < nodeList.size(); i++) {
                        Map<String, Object> map = nodeList.get(i);
                        parent += "'" + map.get("ID") + "'";
                        if (i != nodeList.size() - 1) {
                            parent += ",";
                        }
                    }
                    List<LantopFileShare> lfsList = this.deptdocarrangeService.getShareDataIdsByParentAndDeptId(parent, deptId);
                    String ids = "";
                    for (int i = 0; i < lfsList.size(); i++) {
                        LantopFileShare lfs = lfsList.get(i);
                        ids += "'" + lfs.getRecordId() + "',";
                    }
                    if (ids.length() > 1) {
                        ids = ids.substring(0, ids.length() - 1);
                    }
                    if ("".equals(ids)) {
                        ids = "''";
                    }
                    sb.append(" AND ID IN (" + ids + ")");
                    printQuerySql.append(" AND " + printTableName + ".ID IN (" + ids + ")");
                }
            }
        }
        String highSelectSqlString = "";
        // 高级查询语句
        if (null != whereSql && !"".equals(whereSql)) {
            highSelectSqlString = whereSql.replace("where", " and ").replaceAll("''","'");
        }
        String printHighSelectSqlString = "";
        // 高级查询语句
        if (null != highSelectSql && !"".equals(highSelectSql)) {
            printHighSelectSqlString = highSelectSql.replace("where", " and ");
        }
        // 添加部门文件著录过滤条件
        sb.append(" AND ARCHIVE_SHARE_STATUS = '2'");
        printQuerySql.append(" AND " + printTableName + ".ARCHIVE_SHARE_STATUS = '2'");
        if (null != createdNum && "1".equals(createdNum)) {
            sb.append(" AND (ARCHIVE_CODE IS NULL OR ARCHIVE_CODE  = '')");
            printQuerySql.append(" AND (" + printTableName + ".ARCHIVE_CODE IS NULL OR " + printTableName + ".ARCHIVE_CODE  = '')");
        } else if (null != createdNum && "2".equals(createdNum)) {
            sb.append(" AND (ARCHIVE_CODE IS NOT NULL OR ARCHIVE_CODE  != '')");
            printQuerySql.append(" AND (" + printTableName + ".ARCHIVE_CODE IS NOT NULL OR " + printTableName + ".ARCHIVE_CODE  != '')");
        }
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("userSecretLevel", SessionHelper.getLoginSysUser(request).getSecretLevel());
        Map<String, String> map = this.userAuthIntfsService.getUserAuthDatasByIntfs(orgId, deptId, sysId, "3", SessionHelper.getLoginSysUserId(request), "LANTOP_AUTH_SERVER_USERSET", nodeId, tableId, "", param);
        String authSql = map.get("SQL");
        sb.append(authSql);
        param.put("isEnable", "Y");
        Map<String, String> authmap = this.userAuthIntfsService.getUserAuthDatasByIntfs(orgId, deptId, sysId, "3", SessionHelper.getLoginSysUserId(request), "LANTOP_AUTH_SERVER_USERSET", nodeId, tableId, "", param);
        String authMapSql = authmap.get("SQL");
        printQuerySql.append(authMapSql);
        List<Map<String, Object>> list = null;

        // 定位刷新id,需要定位时，才会有值，不定位时，该值为空
        String selectRecordId = request.getParameter("selectRecordId");
        Map<String, Object> dwParam = new HashMap<String, Object>();
        dwParam.put("TABLE_ID", tableId);
        dwParam.put("PAGE_SIZE", pageSize);
        dwParam.put("SELECT_RECORD_ID", selectRecordId);

        dwParam.put("ORG_ID", orgId);
        dwParam.put("DEPT_ID", deptId);
        dwParam.put("SYS_ID", sysId);

        String searchCondition = "";
        if(null != zlzt && !"".equals(zlzt) && !"null".equals(zlzt)){
        	if("1".equals(zlzt)){
            	searchCondition = " AND (ZLZT = '1' OR ZLZT IS NULL)";
        	}else{
            	searchCondition = " AND ZLZT = '2'";
        	}
        }
        // 根据结果中查询复选框，追加查询条件
        if ("high".equals(searchFlag)) {
            if ("on".equals(highSelectResultSearchFlag)) {
                searchCondition = searchCondition + sb.toString() + searchSb.toString() + highSelectSqlString; 
            } else {
                searchCondition = searchCondition + sb.toString() + highSelectSqlString;
            }
        } else {
            if ("on".equals(resultSearchFlag)) {
                searchCondition = searchCondition + sb.toString() + searchSb.toString() + highSelectSqlString;
            } else {
                searchCondition = searchCondition + sb.toString() + searchSb.toString();
            }
        }

        if (null != selectRecordId && !"".equals(selectRecordId) && !"-1".equals(selectRecordId)) {
            List<String> dwList = this.billDefineManagerIntfsService.getDatasPageNumAndIndexByTableIdRecordId(dwParam, searchCondition);
            String changeNo = dwList.get(0);
            String dataIndex = dwList.get(1);
//            pageNo = changeNo;
            mav.addObject("dataIndex", Double.valueOf(dataIndex).intValue());
        }
        mav.addObject("pageNo", pageNo);

        if (null != tableId && !"".equals(tableId)) {
            list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, tableId, pageNo, pageSize, searchCondition, listParam);
        }

        // this.getAttachNum(list);
        //SanXiaFiles add by huangjian 2019-12-26 四性检测状态
        Map<String, Object> statusParam = new HashMap<String, Object>();
        statusParam.put("tableId", tableId);
        statusParam.put("orgId", orgId);
        statusParam.put("deptId", deptId);
        statusParam.put("sysId", sysId);
        statusParam.put("nodeId", nodeId);
        statusParam.put("stage", "1");//1档案整理，2整理归档，3档案保管
        String dataType = "0";//文件级
        if (!StringUtils.isEmpty(mid) && !"null".equalsIgnoreCase(mid)) {//mid 卷ID
            dataType = "2";//卷内件
        }
        statusParam.put("dataType", dataType);//0文件级 1案卷级 2卷内件
        fourCheckService.getFourCheckStatus(list,statusParam);
        // 判断是否存在库房组件接口
        if (null != storeroommanagerIntfsService) {
            // 数据ids
            String positionIds = "";
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> m = list.get(i);
                positionIds += (String) m.get("ID");
                if (i != list.size() - 1) {
                    positionIds += ",";
                }
            }
            Map<String, Object> positionMap = new HashMap<String, Object>();
            positionMap.put("IDS", positionIds);
            // 通过数据id获取存放位置map
            Map<String, Object> storeMap = this.storeroommanagerIntfsService.getStoreRoomPositionMessageByRecordIdsByIntfs(positionMap);
            // 通过数据id获取存放位置,并添加到存放位置字段中
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> m = list.get(i);
                String id = m.get("ID") + "";
                String position = storeMap.get(id) + "";
                if ("null".equals(position)) {
                    position = "";
                }
                m.put("ARCHIVE_POSITION", position);
            }
        }

        String total = "0";
        if (null != list && list.size() > 0) {
            total = list.get(0).get("ROW_COUNT") + "";
        }
        if (null == list) {
            list = new ArrayList<Map<String, Object>>();
        }

        // 添加日志
        // String searchString = this.billDefineManagerIntfsService.getSearchString(orgId, deptId, sysId, userId, orgCode, nodeId, tableId, json, sessionLanguageCode.toString());
        String modelName = "";
        SysMenu sm = menuAPI.getSysMenuByCode(menuCode, appId);
        if (null != sm) {
            modelName = sm.getName();
        }
        String path = this.archiveClassManagerIntfsService.getModelFileNameByNodeId(nodeId);
        // 条目日志查询记录
        Map<String, Object> paramsLog = new HashMap<String, Object>();
        paramsLog.put("searchType", "1");
        paramsLog.put("modelName", modelName);
        paramsLog.put("tableName", path);
        paramsLog.put("searchCondition", searchString);
        paramsLog.put("searchResultTotal", Integer.parseInt(total));
        paramsLog.put("orgId", orgId);
        paramsLog.put("deptId", deptId);
        paramsLog.put("sysId", sysId);
        // 调用检索日志保存接口
        lantopSearchLogIntfsService.saveLantopSearchLogByMap(paramsLog);

        // 根据结果中查询复选框，追加查询条件
        if ("on".equals(resultSearchFlag)) {
            sb.append(searchSb);

            printQuerySql.append(searchTableSb);
        }
        // 根据高级查询结果中查询复选框，追加查询条件
        if ("on".equals(highSelectResultSearchFlag)) {
            sb.append(highSelectSqlString);
            printQuerySql.append(printHighSelectSqlString);
        }
        /*if(list.size()>0 && list.get(0).containsKey("ARCHIVE_IN_NUM")){
            Collections.sort(list, new Comparator<Map<String, Object>>() {
                @Override
                public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                    return (Integer.parseInt(o1.get("ARCHIVE_IN_NUM").toString()))-(Integer.parseInt(o2.get("ARCHIVE_IN_NUM").toString()));
                }
            });
        }*/

        sb.append(" ORDER BY RQ DESC");
        printQuerySql.append(" ORDER BY ,RQ DESC");
        if(list.size() <= 0 || list == null){

        }

        mav.addObject("publicQuerySql", sb.substring(5, sb.length()));
        mav.addObject("printQuerySql", printQuerySql.substring(5, printQuerySql.length()));
        mav.addObject("total", total);
        mav.addObject("rows", list);
        return mav;
    }

    /**
     * 删除文件目录选中文件集合数据
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/deleteFileDatas")
    public ModelAndView deleteFileDatas(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String type = request.getParameter("type");
        String ids = request.getParameter("ids");
        String anTableId = request.getParameter("anTableId");
        String parentId = request.getParameter("parentId");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        try {
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            Map<String, Object> listParam = new HashMap<String, Object>();
            Map<String, Object> map = new HashMap<String, Object>();
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("modleName", modleName);
            // 如果是案卷目录下文件删除type=delan,如果是案卷拆卷type=chai,如果type=del则是案卷删除,否则是文件删除
            if (null != type && !"".equals(type) && "delAn".equals(type)) {
                map.put("PARENT_ID", "");
                map.put("ARCHIVE_STATUS", -1);
                map.put("ARCHIVE_IN_NUM", "");
            } else if (null != type && !"".equals(type) && "chai".equals(type)) {
                map.put("PARENT_ID", "");
                map.put("ARCHIVE_IN_NUM", "");
            } else if (null != type && !"".equals(type) && "del".equals(type)) {
                // 修改子表数据状态
                String[] anIds = ids.split(";");
                // 文件目录物理表
                List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "2");
                Map<String, Object> fileMap = fileList.get(0);
                String fileTableId = fileMap.get("ID").toString();
                String fileIds = "";
                for (int i = 0; i < anIds.length; i++) {
                    String sql = " AND PARENT_ID = '" + anIds[i] + "'";
                    List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, fileTableId, "1", "100", sql, listParam);
                    for (int j = 0; j < list.size(); j++) {
                        Map<String, Object> mapDel = list.get(j);
                        String id = mapDel.get("ID").toString();
                        fileIds += id;
                        if (j != list.size() - 1 || i != anIds.length - 1) {
                            fileIds += ";";
                        }
                    }
                    if ("".equals(fileIds)) {
                        fileIds = " ";
                    }
                    map.put("ARCHIVE_STATUS", -1);
                    param.put("ajDataId", anIds[i]);
                    this.billDefineManagerIntfsService.updateRecordByDataIdsWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, fileTableId, map, fileIds, param);
                }
            } else {
                map.put("ARCHIVE_STATUS", -1);
            }
            if (null != type && !"".equals(type) && "del".equals(type)) {
                param.put("ajDataId", "");
            } else {
                param.put("ajDataId", parentId);
            }
            this.billDefineManagerIntfsService.updateRecordByDataIdsWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, tableId, map, ids, param);
            if (null != type && null != parentId && !"".equals(type) && ("chai".equals(type) || "delAn".equals(type))) {
                // 处理卷内序号
                Map<String, Object> parameter = new HashMap<String, Object>();
                parameter.put("orgId", orgId);
                parameter.put("deptId", deptId);
                parameter.put("sysId", sysId);
                parameter.put("type", "delete");
                parameter.put("parentId", parentId);
                parameter.put("tableId", tableId);
                parameter.put("modleName", modleName);
                String delIdsSql = ids.replace(";", "','");
                parameter.put("ids", delIdsSql);
                this.billDefineManagerIntfsService.saveOtherArchiveInNumByIntfsByParam(parameter);
            }
            // SanXiaFiles create by zhaoxiaolong 更新起止日期
            this.billDefineManagerIntfsService.UpdateQzrqByAnIdAndAnTableId(parentId,anTableId,null);
            this.billDefineManagerIntfsService.UpdateJsByAnIdAndAnTableId(parentId,anTableId,tableId,orgId,deptId,sysId);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }
    
    /**
     * 加入整理中
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     */
    @RequestMapping("/insertzlzt")
    public ModelAndView insertzlzt(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String ids = request.getParameter("ids");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        try {
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("modleName", modleName);
            Map<String, Object> map = new HashMap<String, Object>();
            //查询整理中最大保管号
            String maxBgh = deptdocarrangeService.getBghBytableName(tableId,nodeId);
            String[] idss = ids.split(";");
            for (int i = 0; i < idss.length; i++) {
            	map.put("ZLH", (Integer.parseInt(maxBgh) + i));
                map.put("ZLZT", "2");
                this.billDefineManagerIntfsService.updateRecordByDataIdsWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, tableId, map, idss[i], param);
			}
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }
    
    /**
     * 移除整理中
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     */
    @RequestMapping("/deletezlzt")
    public ModelAndView deletezlzt(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String ids = request.getParameter("ids");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        try {
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("modleName", modleName);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("ZLH", "");
            map.put("ZLZT", "1");
            this.billDefineManagerIntfsService.updateRecordByDataIdsWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, tableId, map, ids, param);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 撤件时循环更新卷内序号
     *
     * @throws Exception void
     * @author 钟一华
     */
    public void updateFileDataByAnDataIdByChe(String orgId, String deptId, String sysId, String tableId, String
            nodeId, String parentId, String num, String modleName) throws Exception {
        Map<String, Object> listParam = new HashMap<String, Object>();
        String sql = " AND PARENT_ID = '" + parentId + "' AND ARCHIVE_IN_NUM > '" + num + "'";
        List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, tableId, "1", "100", sql, listParam);
        int newNumber = Integer.valueOf(num);
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("ajDataId", parentId);
        param.put("modleName", modleName);
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> map = list.get(i);
            Map<String, Object> updateMap = new HashMap<String, Object>();
            updateMap.put("ARCHIVE_IN_NUM", newNumber);
            // this.billDefineManagerIntfsService.updateRecordByDataIdByIntfs(orgId, deptId, sysId, nodeId, tableId, updateMap, map.get("ID").toString());
            this.billDefineManagerIntfsService.updateRecordByDataIdWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, tableId, updateMap, map.get("ID").toString(), param);
            newNumber++;
        }
    }

    /**
     * 跳转至组卷页面
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/toInstallDataJsp")
    public ModelAndView toInstallDataJsp(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String dialogId = request.getParameter("dialogId");
        String fileTableId = request.getParameter("fileTableId");
        String anTableId = request.getParameter("anTableId");
        String fileIds = request.getParameter("fileIds");
        String nodeId = request.getParameter("nodeId");
        String parentType = request.getParameter("parentType");//SanXiaFiles update by huangjian 2档案类型

        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String orderCols = request.getParameter("orderCols"); // 排序JSON串
        String sysId = request.getParameter("sysId");
        String userId = SessionHelper.getLoginSysUserId(request);
        String dataSecret = request.getParameter("dataSecret");
        String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
        SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
        String orgCode = so.getOrgCode();
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("currentUserId", userId);
        param.put("currentDeptId", deptId);
        param.put("currentOrgCode", orgCode);
        param.put("nodeId", nodeId);
        Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
        param.put("languageCode", sessionLanguageCode);
        try {
            // 案卷动态显示字段集合
            List<Map<String, Object>> anTableList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, anTableId, "2", "", param);
            // String deptCols = this.billDefineManagerIntfsService.getSelectDialogStringByIntfs(orgId, deptId, sysId, anTableId); // 查找选部门，选人的字段字符串
            // Map<String, Map<String, String>> mapCode = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, anTableId);//获取字段通用代码数据//
            // 查找字段生成方式为通用代码的集合
            // mav.addObject("mapCode", mapCode);
            // mav.addObject("deptCols", deptCols);
            /***** 2016/04/22增加 wangzp 页面动态table显示 *****/
            Map<String, Object> colMap1 = new HashMap<String, Object>();
            colMap1.put("COL_NAME_EN", "join");
            colMap1.put("FORMATTER_NAME", "formatJoinAnData");
            if ("zh_CN".equals(sessionLanguageCode)) {
                colMap1.put("COL_NAME_CN", "加入此案卷");
            } else {
                colMap1.put("COL_NAME_CN", "Join The Case");
            }
            List<Map<String, Object>> colList = new ArrayList<Map<String, Object>>();
            colList.add(colMap1);
            Map<String, Object> htmlParam = new HashMap<String, Object>();
            htmlParam.put("datagridId", "mainDatagrid");
            htmlParam.put("datagridUrl", "platform/deptdocarrangeController/getAllAnTableList?tableId=" + anTableId + "&nodeId=" + nodeId + "&sysId=" + sysId + "&startStatus=join");
            htmlParam.put("datagridToolbarId", "toolbar");
            htmlParam.put("domainObjectParam", "deptdocarrange_deptdocarrangeInstall_mainDatagrid"); // 模块名_jsp名_tableid
            htmlParam.put("colList", colList); // 固定列参数
            htmlParam.put("tabColList", anTableList); // 对应显示字段
            /**qht 修改*/
            Map<String, String> currentFormatter = new HashMap<String, String>();
            currentFormatter.put("TM", "formatDetail");
            htmlParam.put("CURRENT_FORMATTER", currentFormatter);
            String fileDatagridHtml = this.billDefineDynamicService.getDatagridHtml(htmlParam);
            mav.addObject("fileDatagridHtml", fileDatagridHtml);

            mav.addObject("fileIds", fileIds);
            mav.addObject("dialogId", dialogId);
            mav.addObject("sysId", sysId);
            mav.addObject("anTableList", anTableList);
            mav.addObject("tableListSize", anTableList.size());
            mav.addObject("fileTableId", fileTableId);
            mav.addObject("anTableId", anTableId);
            mav.addObject("nodeId", nodeId);
            mav.addObject("sysFlag", sysFlag);
            mav.addObject("dataSecret", dataSecret);
            mav.addObject("attachRecordIdKey", "ID");
            mav.addObject("parentType", parentType);
            mav.addObject("attachNodeIdKey", "NODE_ID");
            mav.addObject("orderCols", orderCols);
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeInstall");
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 组卷页面点击新建案卷跳转方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/toAddInstallAnJsp")
    public ModelAndView toAddInstallAnJsp(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String dialogId = request.getParameter("dialogId");
        String fileTableId = request.getParameter("fileTableId");
        String anTableId = request.getParameter("anTableId");
        String fileIds = request.getParameter("fileIds");
        String nodeId = request.getParameter("nodeId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String userId = SessionHelper.getLoginSysUserId(request);
        String dataSecret = request.getParameter("dataSecret");
        //SanXiaFiles update by huangjian 2档案类型
        String parentType = request.getParameter("parentType");
        mav.addObject("parentType", parentType);

        String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
        SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
        String orgCode = so.getOrgCode();
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("currentUserId", userId);
        param.put("currentDeptId", deptId);
        param.put("currentOrgCode", orgCode);
        param.put("nodeId", nodeId);
        Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
        param.put("languageCode", sessionLanguageCode);

        String loginUserSecretLevel = SessionHelper.getLoginSysUser(request).getSecretLevel();
        Map<String, Object> pa = new HashMap<String, Object>();
        pa.put("languageCode", sessionLanguageCode);
        pa.put("userSecretLevel", loginUserSecretLevel);
        try {
            /***** 2015/07/25增加-郭亮-拼接条件sql *****/
            String sql = " AND NODE_ID = '" + nodeId + "' AND ARCHIVE_STATUS = '1'";// 模块固定条件sql
            Map<String, String> userAuthMap = userAuthIntfsService.getUserAuthDatasByIntfs(SessionHelper.getCurrentOrgId(request), SessionHelper.getCurrentDeptId(request), sysId, "3", userId, "LANTOP_AUTH_SERVER_USERSET", nodeId, anTableId, "", null);// 权限Map
            String userAuthsql = userAuthMap.get("SQL");// 权限sql
            sql = sql + userAuthsql;// 最终条件sql
            param.put("userAuthsql", sql);
            /***** 2015/07/25增加-郭亮-拼接条件sql *****/
            param.put("wjIds", fileIds.replace(";", ","));
            // 案卷动态显示字段集合
            List<Map<String, Object>> anFieldList = null;
            //SanXiaFiles update by huiangjian
            if ("2".equals(parentType)) {
                //SanXiaFiles update by huangjian start
                param.put("archiveFlag", "1");//3馆藏，2著录整理  1整理归档
                anFieldList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfsItera(orgId, deptId, sysId, anTableId, "1", "", param);
            } else {
                anFieldList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, anTableId, "1", "", param);
            }

            /** SanXiaFiles create by zhaoxiaolong 生成起止日期 start **/
            StringBuffer tabSql = new StringBuffer();
            tabSql.append("SELECT TABLE_NAME FROM CBB_TABLES WHERE ID='"+anTableId+"'");
            List<Map<String,Object>> tabList = this.jdbcAvicit.getJdbcTemplate().queryForList(tabSql.toString());
            String tableName = "";
            if(tabList.size()>0){
                tableName = tabList.get(0).get("TABLE_NAME").toString();
            }
            StringBuffer sbSql = new StringBuffer();
            sbSql.append("SELECT COL_GENE_METHOD_RULE FROM CBB_TAB_COLUMNS WHERE COL_NAME='QZRQ' AND TABLE_ID='"+anTableId+"'");
            List<Map<String,Object>> listData = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString());
            String colMethodRule = "";
            if(listData.size()>0){
                colMethodRule = (String) listData.get(0).get("COL_GENE_METHOD_RULE");
            }
            // colMethodRule = colMethodRule.trim(); // 去除空格
            String [] colMethodRuleAry = {};
            if(colMethodRule!=""&&"null"!=colMethodRule&&!"null".equals(colMethodRule)&&null!=colMethodRule){
                colMethodRuleAry = colMethodRule.split("\\+");
            }
            if(colMethodRuleAry.length>0){
                StringBuffer qzrqColValue = new StringBuffer(); // 起止日期最后得到的拼接数据
                for (int i = 0;i<colMethodRuleAry.length;i++){
                    // 计算偶数位的拼接字符
                    if(i%2==0){
                        // 奇数 取字段名称
                        String colName = colMethodRuleAry[i].replace(tableName+".","");
                        colName = colName.trim();
                        String colValue = "";
                        for (Map<String,Object> map : anFieldList){
                            if(map.get("COL_NAME").equals(colName)){
                                colValue = map.get("COL_VALUE").toString(); // 获取当前字段对应的值
                                break;
                            }
                        }
                        //colValue = colValue.replaceAll("-","********");
                        qzrqColValue.append(colValue);
                    }else {
                        // 偶数 取拼接字符
                        String zifu = colMethodRuleAry[i].replace("\"","");
                        zifu = zifu.trim();
                        qzrqColValue.append(zifu);
                    }
                }
                for (Map<String,Object> map : anFieldList){
                    //String qzrqValue = qzrqColValue.toString().replace("********","-");
                	String qzrqValue = qzrqColValue.toString().replace("\'","");
                    if(map.get("COL_NAME").equals("QZRQ")){ // 当前字段为起止日期，更新起止日期字段默认值
                        if(qzrqValue.equals("-")){
                            map.put("COL_VALUE","");
                        }else {
                            map.put("COL_VALUE",qzrqValue);
                        }
                        break;
                    }
                }
                /** SanXiaFiles create by zhaoxiaolong 生成起止日期 end **/
            }
            // 文件动态显示字段集合
            List<Map<String, Object>> fileTableList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, fileTableId, "2", "", param);
            String deptCols = this.billDefineManagerIntfsService.getSelectDialogStringByIntfs(orgId, deptId, sysId, anTableId); // 查找选部门，选人的字段字符串
            Map<String, Map<String, String>> mapCode = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, anTableId, "", "1", pa);// 获取字段通用代码数据//
            net.sf.json.JSONArray ja = net.sf.json.JSONArray.fromObject(anFieldList);
            String jaString = ja.toString();
            mav.addObject("dataJson", jaString);
            Map<String, Object> colMap = new HashMap<String, Object>();
            colMap.put("tableId", anTableId);
            colMap.put("nodeId", nodeId);
            colMap.put("sysId", sysId);
            colMap.put("flag", "1");
            colMap.put("orgId", orgId);
            colMap.put("deptId", deptId);
            Map<String, Object> dynamicMap = null;
            if ("2".equals(parentType)) {
                dynamicMap = this.commTableManagerIntfsService.getColumnPageMapItera(colMap, anFieldList);
            } else {
                dynamicMap = this.commTableManagerIntfsService.getColumnPageMap(colMap);
            }
            dynamicMap.put("MODEL_CODE", "deptdocarrangeAddInstallAn");
            dynamicMap.put("FORM_CODE", "addInstallAnForm");
            String addHtml = this.billDefineDynamicService.getDynamicAddHtml(anFieldList, mapCode, dynamicMap);
            mav.addObject("addHtml", addHtml);

            mav.addObject("mapCode", mapCode);
            mav.addObject("deptCols", deptCols);
            mav.addObject("fileIds", fileIds);
            mav.addObject("dialogId", dialogId);
            mav.addObject("sysId", sysId);
            mav.addObject("anFieldList", anFieldList);
            mav.addObject("fileTableList", fileTableList);
            mav.addObject("tableListSize", fileTableList.size());
            mav.addObject("fileTableId", fileTableId);
            mav.addObject("anTableId", anTableId);
            mav.addObject("nodeId", nodeId);
            mav.addObject("sysFlag", sysFlag);
            mav.addObject("dataSecret", dataSecret);
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeAddInstallAn");
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 跳转共享设置页面
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("toShareJsp")
    public ModelAndView toShareJsp(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String dialogId = request.getParameter("dialogId");
        String nodeId = request.getParameter("nodeId");
        String table = request.getParameter("table");
        String tableId = request.getParameter("tableId");
        String ids = request.getParameter("ids");
        String sysId = request.getParameter("sysId");
        mav.addObject("sysId", sysId);
        mav.addObject("dialogId", dialogId);
        mav.addObject("nodeId", nodeId);
        mav.addObject("table", table);
        mav.addObject("tableId", tableId);
        mav.addObject("ids", ids);
        mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeShare");
        return mav;
    }

    /**
     * 获得共享设置信息集合
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getShareList")
    public ModelAndView getShareList(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String ids = request.getParameter("ids");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String[] dataIds = ids.split(";");
        String sqlIds = "";
        for (int i = 0; i < dataIds.length; i++) {
            sqlIds += "'" + dataIds[i] + "',";
        }
        sqlIds = sqlIds.substring(0, sqlIds.length() - 1);
        try {
            List<Map<String, Object>> list = this.deptdocarrangeService.getSharelist(nodeId, tableId, sqlIds);
            String total = "0";
            if (null != list && list.size() > 0) {
                total = list.size() + "";
            }
            mav.addObject("total", total);
            mav.addObject("rows", list);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 跳转共享设置添加页面
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/toSelectJsp")
    public ModelAndView toSelectJsp(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String dialogId = request.getParameter("dialogId");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String table = request.getParameter("table");
        String ids = request.getParameter("ids");
        String sysId = request.getParameter("sysId");
        mav.addObject("sysId", sysId);
        mav.addObject("dialogId", dialogId);
        mav.addObject("nodeId", nodeId);
        mav.addObject("tableId", tableId);
        mav.addObject("table", table);
        mav.addObject("ids", ids);
        mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeSelect");
        return mav;
    }

    /**
     * 保存共享数据方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/saveFileShare")
    public ModelAndView saveFileShare(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String table = request.getParameter("table");
        String ids = request.getParameter("ids");
        String loginUserId = SessionHelper.getLoginSysUserId(request);
        Map<String, Object> map = JsonUtils.newInstance().Json2Bean2Form(request.getParameter("datas"), HashMap.class);
        String userIds = map.get("userIds").toString();
        String deptIds = map.get("deptIds").toString();
        String[] dataIds = ids.split(";");
        String[] uIds = null;
        String[] dIds = null;
        Map<String, Object> listParam = new HashMap<String, Object>();
        if (null != userIds && !"".equals(userIds)) {
            uIds = userIds.split(",");
        } else {
            uIds = new String[0];
        }
        if (null != deptIds && !"".equals(deptIds)) {
            dIds = deptIds.split(",");
        } else {
            dIds = new String[0];
        }
        String sysId = request.getParameter("sysId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        boolean isSave = false;
        try {
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            isSave = this.deptdocarrangeService.checkFileShareByRecordIdAndShareDeptIdsAndShareUserIds(dataIds, dIds, uIds);
            if (isSave == false) {
                boolean isTrue = false;
                for (int i = 0; i < uIds.length; i++) {
                    if (loginUserId.equals(uIds[i])) {
                        isTrue = true;
                        break;
                    }
                }
                for (int i = 0; i < dIds.length; i++) {
                    if (deptId.equals(dIds[i])) {
                        isTrue = true;
                        break;
                    }
                }
                if (isTrue) {
                    mav.addObject("isTrue", isTrue);
                } else {
                    List<Map<String, Object>> list = this.archiveClassManagerIntfsService.getArchiveClassListInfoByIntfs(nodeId);
                    String nodePath = "";
                    if (list.size() > 0) {
                        Map<String, Object> nodeMap = list.get(0);
                        nodePath = nodeMap.get("ARCHIVE_CLASS_NODE_PATH").toString();
                    }
                    // 所选节点对应物理表信息
                    List<Map<String, Object>> allList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "");
                    String tableName = "";
                    String tableTitle = "";
                    String childTableId = "";
                    String childTableName = "";
                    String childTableTitle = "";
                    String childIdsString = "";
                    List<String> childIds = new ArrayList<String>();
                    List<Map<String, Object>> childDataList = new ArrayList<Map<String, Object>>();
                    if (allList.size() == 1) {
                        if (table.equals("file")) {
                            // 文件目录标签页物理表信息
                            List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "1");
                            Map<String, Object> fileMap = fileList.get(0);
                            tableName = fileMap.get("TABLE_NAME").toString();
                            tableTitle = fileMap.get("TABLE_TITLE").toString();
                        } else {
                            tableName = "LANTOP_ARC_BOX_CATA";
                            tableTitle = "盒目录";
                            // 文件目录标签页物理表信息
                            List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "1");
                            Map<String, Object> fileMap = fileList.get(0);
                            childTableId = fileMap.get("ID").toString();
                            childTableName = fileMap.get("TABLE_NAME").toString();
                            childTableTitle = fileMap.get("TABLE_TITLE").toString();
                            String searchChildSql = " AND PARENT_ID IN (";
                            for (int i = 0; i < dataIds.length; i++) {
                                searchChildSql += "'" + dataIds[i] + "',";
                            }
                            searchChildSql = searchChildSql.substring(0, searchChildSql.length() - 1);
                            searchChildSql += ")";
                            childDataList = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByNoChangeByIntfs(orgId, deptId, sysId, childTableId, "", "", searchChildSql, listParam);
                            for (int i = 0; i < childDataList.size(); i++) {
                                Map<String, Object> childDataMap = childDataList.get(i);
                                childIds.add(childDataMap.get("ID").toString());
                                childIdsString += childDataMap.get("ID") + ";";
                            }
                            if (childIdsString.length() > 1) {
                                childIdsString = childIdsString.substring(0, childIdsString.length() - 1);
                            }
                        }
                    }
                    if (allList.size() >= 2) {
                        if (table.equals("file")) {
                            // 文件目录标签页物理表信息
                            List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "2");
                            Map<String, Object> fileMap = fileList.get(0);
                            tableName = fileMap.get("TABLE_NAME").toString();
                            tableTitle = fileMap.get("TABLE_TITLE").toString();
                        } else {
                            // 案卷目录标签页物理表信息
                            List<Map<String, Object>> anList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "1");
                            Map<String, Object> anMap = anList.get(0);
                            tableName = anMap.get("TABLE_NAME").toString();
                            tableTitle = anMap.get("TABLE_TITLE").toString();
                            // 文件目录标签物理表信息
                            List<Map<String, Object>> childList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "2");
                            Map<String, Object> childMap = childList.get(0);
                            childTableId = childMap.get("ID").toString();
                            childTableName = childMap.get("TABLE_NAME").toString();
                            childTableTitle = childMap.get("TABLE_TITLE").toString();
                            String searchChildSql = " AND PARENT_ID IN (";
                            for (int i = 0; i < dataIds.length; i++) {
                                searchChildSql += "'" + dataIds[i] + "',";
                            }
                            searchChildSql = searchChildSql.substring(0, searchChildSql.length() - 1);
                            searchChildSql += ")";
                            childDataList = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, childTableId, "1", "100", searchChildSql, listParam);
                            for (int i = 0; i < childDataList.size(); i++) {
                                Map<String, Object> childDataMap = childDataList.get(i);
                                childIds.add(childDataMap.get("ID").toString());
                                childIdsString += childDataMap.get("ID") + ";";
                            }
                            if (childIdsString.length() > 1) {
                                childIdsString = childIdsString.substring(0, childIdsString.length() - 1);
                            }
                        }
                    }
                    for (int i = 0; i < uIds.length; i++) {
                        for (int j = 0; j < dataIds.length; j++) {
                            LantopFileShare lfs = new LantopFileShare();
                            lfs.setArchiveTableId(tableId);
                            lfs.setArchiveTableName(tableName);
                            lfs.setArchiveTableTitle(tableTitle);
                            lfs.setArchiveClassNodePath(nodePath);
                            lfs.setArchiveClassId(nodeId);
                            lfs.setOrgId(orgId);
                            lfs.setDeptId(deptId);
                            lfs.setSysId(sysId);
                            lfs.setShareUserId(uIds[i]);
                            lfs.setRecordId(dataIds[j]);
                            this.deptdocarrangeService.saveFileShare(lfs);
                        }
                    }
                    for (int i = 0; i < dIds.length; i++) {
                        for (int j = 0; j < dataIds.length; j++) {
                            LantopFileShare lfs = new LantopFileShare();
                            lfs.setArchiveTableId(tableId);
                            lfs.setArchiveTableName(tableName);
                            lfs.setArchiveTableTitle(tableTitle);
                            lfs.setArchiveClassNodePath(nodePath);
                            lfs.setArchiveClassId(nodeId);
                            lfs.setOrgId(orgId);
                            lfs.setDeptId(deptId);
                            lfs.setSysId(sysId);
                            lfs.setShareDeptId(dIds[i]);
                            lfs.setRecordId(dataIds[j]);
                            this.deptdocarrangeService.saveFileShare(lfs);
                        }
                    }
                    if (table.equals("an")) {
                        for (int i = 0; i < uIds.length; i++) {
                            for (int j = 0; j < childIds.size(); j++) {
                                LantopFileShare lfs = new LantopFileShare();
                                lfs.setArchiveTableId(childTableId);
                                lfs.setArchiveTableName(childTableName);
                                lfs.setArchiveTableTitle(childTableTitle);
                                lfs.setArchiveClassNodePath(nodePath);
                                lfs.setArchiveClassId(nodeId);
                                lfs.setOrgId(orgId);
                                lfs.setDeptId(deptId);
                                lfs.setSysId(sysId);
                                lfs.setShareUserId(uIds[i]);
                                lfs.setRecordId(childIds.get(j));
                                this.deptdocarrangeService.saveFileShare(lfs);
                            }
                        }
                        for (int i = 0; i < dIds.length; i++) {
                            for (int j = 0; j < childIds.size(); j++) {
                                LantopFileShare lfs = new LantopFileShare();
                                lfs.setArchiveTableId(childTableId);
                                lfs.setArchiveTableName(childTableName);
                                lfs.setArchiveTableTitle(childTableTitle);
                                lfs.setArchiveClassNodePath(nodePath);
                                lfs.setArchiveClassId(nodeId);
                                lfs.setOrgId(orgId);
                                lfs.setDeptId(deptId);
                                lfs.setSysId(sysId);
                                lfs.setShareDeptId(dIds[i]);
                                lfs.setRecordId(childIds.get(j));
                                this.deptdocarrangeService.saveFileShare(lfs);
                            }
                        }
                    }
                    mav.addObject("isTrue", isTrue);
                    Map<String, Object> updateMap = new HashMap<String, Object>();
                    updateMap.put("ARCHIVE_SHARE_STATUS", "1");
                    Map<String, Object> param = new HashMap<String, Object>();
                    param.put("ajDataId", "");
                    param.put("modleName", modleName);
                    this.billDefineManagerIntfsService.updateRecordByDataIdsWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, tableId, updateMap, ids, param);
                    if (table.equals("an") && !"".equals(childIdsString)) {
                        this.billDefineManagerIntfsService.updateRecordByDataIdsWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, childTableId, updateMap, childIdsString, param);
                    }
                }
            }
            mav.addObject("isSave", isSave);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 删除共享设置中选中数据
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/deleteShareDatas")
    public ModelAndView deleteShareDatas(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String sids = request.getParameter("shareIds");
        String rids = request.getParameter("recordIds");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String sysId = request.getParameter("sysId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        try {
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            String[] shareIds = sids.split(";");
            String[] recordIds = rids.split(";");
            String shareSqlIds = "";
            String recordSqlIds = "";
            for (int i = 0; i < shareIds.length; i++) {
                shareSqlIds += "'" + shareIds[i] + "',";
            }
            shareSqlIds = shareSqlIds.substring(0, shareSqlIds.length() - 1);
            for (int i = 0; i < recordIds.length; i++) {
                recordSqlIds += "'" + recordIds[i] + "',";
            }
            recordSqlIds = recordSqlIds.substring(0, recordSqlIds.length() - 1);
            List<Map<String, Object>> list = this.deptdocarrangeService.getShareListByRecordIdsAndShareIds(nodeId, tableId, shareSqlIds, recordSqlIds);
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> map = list.get(i);
                this.deptdocarrangeService.deleteShareData(map.get("ID").toString());
            }
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("ajDataId", "");
            param.put("modleName", modleName);
            for (int i = 0; i < recordIds.length; i++) {
                boolean isExist = this.deptdocarrangeService.isExistShareByRecordId(recordIds[i]);
                if (isExist == false) {
                    Map<String, Object> updateMap = new HashMap<String, Object>();
                    updateMap.put("ARCHIVE_SHARE_STATUS", "0");
                    // this.billDefineManagerIntfsService.updateRecordByDataIdByIntfs(orgId, deptId, sysId, nodeId, tableId, updateMap, recordIds[i]);
                    this.billDefineManagerIntfsService.updateRecordByDataIdWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, tableId, updateMap, recordIds[i], param);
                }
            }
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 通过ids获得动态数据
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getFileDatasByIds")
    public ModelAndView getFileDatasByIds(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String tableId = request.getParameter("fileTableId");
        String fileIds = request.getParameter("fileIds");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String pageNo = request.getParameter("page");
        String pageSize = request.getParameter("rows");
        String sysId = request.getParameter("sysId");
        String[] ids = null;
        if (null != fileIds && !"".equals(fileIds)) {
            ids = fileIds.split(";");
        }
        Map<String, Object> listParam = new HashMap<String, Object>();
        List<Map<String, Object>> searchList = new ArrayList<Map<String, Object>>();
        if (null != ids) {
            for (int i = 0; i < ids.length; i++) {
                String sql = " and ID = '" + ids[i] + "'";
                List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, tableId, pageNo, pageSize, sql, listParam);
                searchList.add(list.get(0));
            }
        }
        // this.getAttachNum(searchList);

        // 判断是否存在库房组件接口
        if (null != storeroommanagerIntfsService) {
            // 数据ids
            String positionIds = "";
            for (int i = 0; i < searchList.size(); i++) {
                Map<String, Object> m = searchList.get(i);
                positionIds += (String) m.get("ID");
                if (i != searchList.size() - 1) {
                    positionIds += ",";
                }
            }
            Map<String, Object> positionMap = new HashMap<String, Object>();
            positionMap.put("IDS", positionIds);
            // 通过数据id获取存放位置map
            Map<String, Object> storeMap = this.storeroommanagerIntfsService.getStoreRoomPositionMessageByRecordIdsByIntfs(positionMap);
            // 通过数据id获取存放位置,并添加到存放位置字段中
            for (int i = 0; i < searchList.size(); i++) {
                Map<String, Object> m = searchList.get(i);
                String id = m.get("ID") + "";
                String position = storeMap.get(id) + "";
                if ("null".equals(position)) {
                    position = "";
                }
                m.put("ARCHIVE_POSITION", position);
            }
        }

        String total = "0";
        if (null != searchList && searchList.size() > 0) {
            total = searchList.size() + "";
        }
        mav.addObject("total", total);
        mav.addObject("rows", searchList);
        return mav;
    }

    /**
     * 将选中文件ids的数据更新为传递id案卷的子数据
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/saveAndUpdateInstallDatas")
    public ModelAndView saveAndUpdateInstallDatas(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String fileIds = request.getParameter("fileIds");
        Map<String, Object> map = JsonUtils.newInstance().Json2Bean2Form(request.getParameter("datas"), HashMap.class);
        String nodeId = request.getParameter("nodeId");
        String fileTableId = request.getParameter("fileTableId");
        String anTableId = request.getParameter("anTableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String loginUserId = SessionHelper.getLoginSysUserId(request);
        String loginIp = SessionHelper.getClientIp(request);
        map.put("ORG_ID", orgId);
        map.put("DEPT_ID", deptId);
        map.put("SYS_ID", sysId);
        map.put("NODE_ID", nodeId);
        map.put("ARCHIVE_STATUS", "1");
        map.put("ARCHIVE_FLOW_STATUS", "1");
        map.put("ARCHIVE_SHARE_STATUS", "0");
        map.put("ARCHIVE_STATUS", "0");
        try {
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            String[] ids = fileIds.split(";");
            // String sql = " AND ID IN (";
            // for (int i = 0; i < ids.length; i++) {
            // sql += "'" + ids[i] + "',";
            // }
            // sql = sql.substring(0, sql.length() - 1);
            // sql += ")";
            // //获得页数总和
            // Object copyObj = this.billDefineManagerIntfsService.getOperationTableColDataByIntfs(fileTableId, sql, "ARCHIVE_COPY_NUM", orgId, deptId, sysId, "SUM");
            // Object pageObj = this.billDefineManagerIntfsService.getOperationTableColDataByIntfs(fileTableId, sql, "ARCHIVE_PAGE_NUM", orgId, deptId, sysId, "SUM");
            // if (null != copyObj) {
            // map.put("ARCHIVE_COPY_NUM", copyObj);
            // }
            // if (null != pageObj) {
            // map.put("ARCHIVE_PAGE_NUM", pageObj);
            // }
            // String resultId = this.billDefineManagerIntfsService.insertRecordByIntfs(orgId, deptId, sysId, nodeId, anTableId, map, loginUserId, loginIp);
            Map<String, Object> paramIds = new HashMap<String, Object>();
            paramIds.put("wjIds", fileIds);
            List<Map<String, Object>> listObj = new ArrayList<Map<String, Object>>();
            listObj.add(map);
            paramIds.put("modleName", modleName);
            String newIds = this.billDefineManagerIntfsService.insertRecordByBatchByIntfs(orgId, deptId, sysId, nodeId, anTableId, listObj, loginUserId, loginIp, paramIds);
            String resultId = (String) map.get("ID");

            Map<String, Object> mapObj = new HashMap<String, Object>();
            mapObj.put("PARENT_ID", resultId);
            int num = 1;
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("ajDataId", resultId);
            param.put("modleName", modleName);
            for (int i = 0; i < ids.length; i++) {
                mapObj.put("ARCHIVE_IN_NUM", num);
                // this.billDefineManagerIntfsService.updateRecordByDataIdByIntfs(orgId, deptId, sysId, nodeId, fileTableId, mapObj, ids[i]);
                this.billDefineManagerIntfsService.updateRecordByDataIdWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, fileTableId, mapObj, ids[i], param);
                num++;
            }
            // SanXiaFiles create by zhaoxiaolong 更新起止日期
            this.billDefineManagerIntfsService.UpdateQzrqByAnIdAndAnTableId(newIds,anTableId,null);
            // this.billDefineManagerIntfsService.updateRecordByDataIdsByIntfs(orgId, deptId, sysId, nodeId, fileTableId, mapObj, fileIds);
            mav.addObject("ID", resultId);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 组卷中加入方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/updateInstallDatas")
    public ModelAndView updateInstallDatas(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String anTableId = request.getParameter("anTableId");
        String resultId = request.getParameter("anId");
        String fileIds = request.getParameter("fileIds");
        String nodeId = request.getParameter("nodeId");
        String fileTableId = request.getParameter("fileTableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        try {
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            // Map<String, Object> m = new HashMap<String, Object>();
            String[] ids = fileIds.split(";");
            // String sumSql = " AND ID IN (";
            // for (int i = 0; i < ids.length; i++) {
            // sumSql += "'" + ids[i] + "',";
            // }
            // sumSql = sumSql.substring(0, sumSql.length() - 1);
            // sumSql += ")";
            // //获得页数总和
            // Object copyObj = this.billDefineManagerIntfsService.getOperationTableColDataByIntfs(fileTableId, sumSql, "ARCHIVE_COPY_NUM", orgId, deptId, sysId, "SUM");
            // Object pageObj = this.billDefineManagerIntfsService.getOperationTableColDataByIntfs(fileTableId, sumSql, "ARCHIVE_PAGE_NUM", orgId, deptId, sysId, "SUM");
            // String searchSql = " AND ID = '" + resultId + "'";
            // List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByIntfs(orgId, deptId, sysId, anTableId, "1", "100", searchSql);
            // Object cObj = null;
            // Object pObj = null;
            // if (list.size() > 0) {
            // Map<String, Object> resultMap = list.get(0);
            // cObj = resultMap.get("ARCHIVE_COPY_NUM");
            // pObj = resultMap.get("ARCHIVE_PAGE_NUM");
            // }
            // if (null != copyObj && !"".equals(copyObj) && !"null".equals(copyObj)) {
            // if (null != cObj && !"".equals(cObj) && !"null".equals(cObj)) {
            // int numCopy = Integer.valueOf(copyObj.toString());
            // int numC = Integer.valueOf(cObj.toString());
            // m.put("ARCHIVE_COPY_NUM", numCopy + numC);
            // } else {
            // m.put("ARCHIVE_COPY_NUM", copyObj);
            // }
            //
            // }
            // if (null != pageObj && !"".equals(pageObj) && !"null".equals(pageObj)) {
            // if (null != pObj && !"".equals(pObj) && !"null".equals(pObj)) {
            // int numPage = Integer.valueOf(pageObj.toString());
            // int numP = Integer.valueOf(pObj.toString());
            // m.put("ARCHIVE_PAGE_NUM", numPage + numP);
            // } else {
            // m.put("ARCHIVE_PAGE_NUM", pageObj);
            // }
            // }
            // this.billDefineManagerIntfsService.updateRecordByDataIdByIntfs(orgId, deptId, sysId, nodeId, anTableId, m, resultId);
            // Map<String, Object> mapObj = new HashMap<String, Object>();
            // mapObj.put("PARENT_ID", resultId);
            // this.billDefineManagerIntfsService.updateRecordByDataIdsByIntfs(orgId, deptId, sysId, nodeId, fileTableId, mapObj, fileIds);
            Map<String, String> searchMap = new HashMap<String, String>();
            searchMap.put("PARENT_ID", "'" + resultId + "'");
            String sql = " AND PARENT_ID = '" + resultId + "'";
            // Object obj = this.billDefineManagerIntfsService.getMaxTableColDataByIntfs(fileTableId, searchMap, "ARCHIVE_IN_NUM", orgId, deptId, sysId);
            Object obj = this.billDefineManagerIntfsService.getOperationTableColDataByIntfs(fileTableId, sql, "ARCHIVE_IN_NUM", orgId, deptId, sysId, "MAX");
            int num = 0;
            if (null != obj) {
                num = Integer.valueOf(obj.toString()) + 1;
            } else {
                num = num + 1;
            }
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("ajDataId", resultId);
            param.put("modleName", modleName);
            for (int i = 0; i < ids.length; i++) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("ARCHIVE_IN_NUM", num);
                map.put("PARENT_ID", resultId);
                // this.billDefineManagerIntfsService.updateRecordByDataIdByIntfs(orgId, deptId, sysId, nodeId, fileTableId, map, ids[i]);
                this.billDefineManagerIntfsService.updateRecordByDataIdWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, fileTableId, map, ids[i], param);
                num++;
            }
            /** SanXiaFiles create by zhaoxiaolong 更改新起止日期 start **/
            this.billDefineManagerIntfsService.UpdateQzrqByAnIdAndAnTableId(resultId,anTableId,null);
            /** SanXiaFiles create by zhaoxiaolong 更改新起止日期 end **/
            this.billDefineManagerIntfsService.UpdateJsByAnIdAndAnTableId(resultId,anTableId, fileTableId, orgId, deptId, sysId);

            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 跳转回收站方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/toFileRecycleJsp")
    public ModelAndView toFileRecycleJsp(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String nodeId = request.getParameter("nodeId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String userId = SessionHelper.getLoginSysUserId(request);
        String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
        SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
        //SanXiaFiles update by huangjian 2档案类型
        String parentType = request.getParameter("parentType");
        mav.addObject("parentType", parentType);
        //SanXiaFiles update by huangjian end
        String orgCode = so.getOrgCode();
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("currentUserId", userId);
        param.put("currentDeptId", deptId);
        param.put("currentOrgCode", orgCode);
        param.put("nodeId", nodeId);
        Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
        param.put("languageCode", sessionLanguageCode);

        String loginUserSecretLevel = SessionHelper.getLoginSysUser(request).getSecretLevel();
        Map<String, Object> pa = new HashMap<String, Object>();
        pa.put("languageCode", sessionLanguageCode);
        pa.put("userSecretLevel", loginUserSecretLevel);
        try {
            // 所选节点对应物理表信息
            List<Map<String, Object>> allList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "");
            if (allList.size() == 1) {
                // 文件目录标签页物理表信息
                List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "1");
                Map<String, Object> fileMap = fileList.get(0);
                String fileId = fileMap.get("ID").toString();
                // 文件动态查询字段集合
                List<Map<String, Object>> fileSearchList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, fileId, "4", "", param);
                // 文件动态显示字段集合
                List<Map<String, Object>> fileTableList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, fileId, "2", "", param);
                String fileDeptCols = this.billDefineManagerIntfsService.getSelectDialogStringByIntfs(orgId, deptId, sysId, fileId); // 查找选部门，选人的字段字符串
                Map<String, Map<String, String>> fileMapCode = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, fileId, "", "4", pa);// 获取字段通用代码数据//
                mav.addObject("fileMapCode", fileMapCode);
                mav.addObject("fileDeptCols", fileDeptCols);
                mav.addObject("fileTableId", fileId);
                mav.addObject("fileSearchList", fileSearchList);
                mav.addObject("fileTableList", fileTableList);
                mav.addObject("fileTableListSize", fileTableList.size());

                /***** 2016/04/21增加 wangzp 页面动态form显示 *****/
                Map<String, Object> colFileMap = new HashMap<String, Object>();
                colFileMap.put("tableId", fileId);
                colFileMap.put("nodeId", nodeId);
                colFileMap.put("sysId", sysId);
                colFileMap.put("flag", "4");
                colFileMap.put("orgId", orgId);
                colFileMap.put("deptId", deptId);
                Map<String, Object> dynamicFileMap = this.commTableManagerIntfsService.getColumnPageMap(colFileMap);
                dynamicFileMap.put("MODEL_CODE", "deptdocarrangeRecycleFile");
                dynamicFileMap.put("FORM_CODE", "searchFileForm");
                dynamicFileMap.put("ALIAS_NAME", "FILE");
                String searchFileHtml = this.billDefineDynamicService.getDynamicSearchHtml(fileSearchList, fileMapCode, dynamicFileMap);
                mav.addObject("searchFileHtml", searchFileHtml);
                /* TODO NO.1[更改详细列]去除全文改为题名查看详情 create by 赵晓龙 */
                List<Map<String, Object>> listCloumData = new ArrayList<>();
                for (Map<String, Object> map : fileTableList) {
                    String name = map.get("COL_NAME") == null ? "" : map.get("COL_NAME").toString();
                    if (name.equals("TM")) {
                        map.put("FORMATTER", "formatDetailText");
                    }
                    listCloumData.add(map);
                }
                /***** 2016/04/21增加 wangzp 页面动态table显示 *****/
                /*Map<String, Object> colMap1 = new HashMap<String, Object>();
                colMap1.put("COL_NAME_EN", "ATTACH_SIZE");
                colMap1.put("FORMATTER_NAME", "formatAllText");
                Map<String, Object> colMap3 = new HashMap<String, Object>();
                colMap3.put("COL_NAME_EN", "3");
                colMap3.put("FORMATTER_NAME", "formatDetailText");
                if ("zh_CN".equals(sessionLanguageCode)) {
                    colMap1.put("COL_NAME_CN", "全文");
                    colMap3.put("COL_NAME_CN", "详细");
                } else {
                    colMap1.put("COL_NAME_CN", "Full Text");
                    colMap3.put("COL_NAME_CN", "Detail");
                }
                List<Map<String, Object>> colList = new ArrayList<Map<String, Object>>();
                colList.add(colMap1);
                colList.add(colMap3);*/
                Map<String, Object> htmlParam = new HashMap<String, Object>();
                htmlParam.put("datagridId", "fileDatagrid");
                htmlParam.put("datagridUrl", "platform/deptdocarrangeController/getRecycleFileTableList?nodeId=" + nodeId + "&fileTableId=" + fileId + "&sysId=" + sysId + " ");
                htmlParam.put("datagridToolbarId", "searchDiv");
                htmlParam.put("domainObjectParam", "deptdocarrange_deptdocarrangeRecycleIframe_fileDatagrid"); // 模块名_jsp名_tableid
                // htmlParam.put("colList", colList); // 固定列参数
                htmlParam.put("tabColList", listCloumData); // 对应显示字段
                String recyFileDatagridHtml = this.billDefineDynamicService.getDatagridHtml(htmlParam);
                mav.addObject("recyFileDatagridHtml", recyFileDatagridHtml);

            }
            if (allList.size() >= 2) {
                // 文件目录标签页物理表信息
                List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "2");
                Map<String, Object> fileMap = fileList.get(0);
                String fileId = fileMap.get("ID").toString();
                // 文件动态查询字段集合
                List<Map<String, Object>> fileSearchList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, fileId, "4", "", param);
                // 文件动态显示字段集合
                List<Map<String, Object>> fileTableList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, fileId, "2", "", param);
                String fileDeptCols = this.billDefineManagerIntfsService.getSelectDialogStringByIntfs(orgId, deptId, sysId, fileId); // 查找选部门，选人的字段字符串
                Map<String, Map<String, String>> fileMapCode = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, fileId, "", "4", pa);// 获取字段通用代码数据//
                mav.addObject("fileMapCode", fileMapCode);
                mav.addObject("fileDeptCols", fileDeptCols);
                mav.addObject("fileTableId", fileId);
                mav.addObject("fileSearchList", fileSearchList);
                mav.addObject("fileTableList", fileTableList);
                mav.addObject("fileTableListSize", fileTableList.size());
                /***** 2016/04/21增加 wangzp 页面动态form显示 *****/
                Map<String, Object> colFileMap = new HashMap<String, Object>();
                colFileMap.put("tableId", fileId);
                colFileMap.put("nodeId", nodeId);
                colFileMap.put("sysId", sysId);
                colFileMap.put("flag", "4");
                colFileMap.put("orgId", orgId);
                colFileMap.put("deptId", deptId);
                Map<String, Object> dynamicFileMap = this.commTableManagerIntfsService.getColumnPageMap(colFileMap);
                dynamicFileMap.put("MODEL_CODE", "deptdocarrangeRecycleFile");
                dynamicFileMap.put("FORM_CODE", "searchFileForm");
                dynamicFileMap.put("ALIAS_NAME", "FILE");
                String searchFileHtml = this.billDefineDynamicService.getDynamicSearchHtml(fileSearchList, fileMapCode, dynamicFileMap);
                mav.addObject("searchFileHtml", searchFileHtml);
                /* TODO NO.2[更改详细列]去除全文改为题名查看详情 create by 赵晓龙 */
                List<Map<String, Object>> listCloumData = new ArrayList<>();
                for (Map<String, Object> map : fileTableList) {
                    String name = map.get("COL_NAME") == null ? "" : map.get("COL_NAME").toString();
                    if (name.equals("TM")) {
                        map.put("FORMATTER", "formatDetailText");
                    }
                    listCloumData.add(map);
                }
                /***** 2016/04/21增加 wangzp 页面动态table显示 *****/
               /* Map<String, Object> colMap1 = new HashMap<String, Object>();
                colMap1.put("COL_NAME_EN", "ATTACH_SIZE");
                colMap1.put("FORMATTER_NAME", "formatAllText");
                Map<String, Object> colMap3 = new HashMap<String, Object>();
                colMap3.put("COL_NAME_EN", "3");
                colMap3.put("FORMATTER_NAME", "formatDetailText");
                if ("zh_CN".equals(sessionLanguageCode)) {
                    colMap1.put("COL_NAME_CN", "全文");
                    colMap3.put("COL_NAME_CN", "详细");
                } else {
                    colMap1.put("COL_NAME_CN", "Full Text");
                    colMap3.put("COL_NAME_CN", "Detail");
                }
                List<Map<String, Object>> colList = new ArrayList<Map<String, Object>>();
                colList.add(colMap1);
                colList.add(colMap3);*/
                Map<String, Object> htmlParam = new HashMap<String, Object>();
                htmlParam.put("datagridId", "fileDatagrid");
                htmlParam.put("datagridUrl", "platform/deptdocarrangeController/getRecycleFileTableList?nodeId=" + nodeId + "&fileTableId=" + fileId + "&sysId=" + sysId + " ");
                htmlParam.put("datagridToolbarId", "searchDiv");
                htmlParam.put("domainObjectParam", "deptdocarrange_deptdocarrangeRecycleIframe_fileDatagrid"); // 模块名_jsp名_tableid
                // htmlParam.put("colList", colList); // 固定列参数
                htmlParam.put("tabColList", listCloumData); // 对应显示字段
                String recyFileDatagridHtml = this.billDefineDynamicService.getDatagridHtml(htmlParam);
                mav.addObject("recyFileDatagridHtml", recyFileDatagridHtml);

                // 案卷目录标签页物理表信息
                List<Map<String, Object>> anList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "1");
                Map<String, Object> anMap = anList.get(0);
                String anId = anMap.get("ID").toString();
                // 案卷动态查询字段集合
                List<Map<String, Object>> anSearchList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, anId, "4", "", param);
                // 案卷动态显示字段集合
                List<Map<String, Object>> anTableList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, anId, "2", "", param);
                String anDeptCols = this.billDefineManagerIntfsService.getSelectDialogStringByIntfs(orgId, deptId, sysId, anId); // 查找选部门，选人的字段字符串
                Map<String, Map<String, String>> anMapCode = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, anId, "", "4", pa);// 获取字段通用代码数据//
                /***** 2016/04/21增加 wangzp 页面动态form显示 *****/
                Map<String, Object> colErMap = new HashMap<String, Object>();
                colErMap.put("tableId", anId);
                colErMap.put("nodeId", nodeId);
                colErMap.put("sysId", sysId);
                colErMap.put("flag", "4");
                colErMap.put("orgId", orgId);
                colErMap.put("deptId", deptId);
                Map<String, Object> dynamicErMap = this.commTableManagerIntfsService.getColumnPageMap(colErMap);
                // 案卷目录
                dynamicErMap.put("MODEL_CODE", "deptdocarrangeRecycleAn");
                dynamicErMap.put("FORM_CODE", "searchAnForm");
                dynamicErMap.put("ALIAS_NAME", "AN");
                String searchErHtml = this.billDefineDynamicService.getDynamicSearchHtml(anSearchList, anMapCode, dynamicErMap);
                mav.addObject("searchAnHtml", searchErHtml);
                /***** 2016/04/19增加 wangzp 页面动态table显示 *****/
                // 绘制案卷目录table(主)
                /* TODO NO.3[更改详细列]去除全文改为题名查看详情 create by 赵晓龙 */
                List<Map<String, Object>> listCloumDatas = new ArrayList<>();
                for (Map<String, Object> map : anTableList) {
                    String name = map.get("COL_NAME") == null ? "" : map.get("COL_NAME").toString();
                    if (name.equals("TM")) {
                        map.put("FORMATTER", "formatDetailText");
                    }
                    listCloumDatas.add(map);
                }
               /* Map<String, Object> colMapAn1 = new HashMap<String, Object>();
                colMapAn1.put("COL_NAME_EN", "ATTACH_SIZE");
                colMapAn1.put("COL_NAME_CN", "全文");
                colMapAn1.put("FORMATTER_NAME", "formatAllText");
                Map<String, Object> colMapAn3 = new HashMap<String, Object>();
                colMapAn3.put("COL_NAME_EN", "3");
                colMapAn3.put("COL_NAME_CN", "详细");
                colMapAn3.put("FORMATTER_NAME", "formatDetailText");
                if ("zh_CN".equals(sessionLanguageCode)) {
                    colMapAn1.put("COL_NAME_CN", "全文");
                    colMapAn3.put("COL_NAME_CN", "详细");
                } else {
                    colMapAn1.put("COL_NAME_CN", "Full Text");
                    colMapAn3.put("COL_NAME_CN", "Detail");
                }
                List<Map<String, Object>> colListAn = new ArrayList<Map<String, Object>>();
                if (!"JTB".equals(this.sysFlag)) {
                    colListAn.add(colMapAn1);
                }
                colListAn.add(colMapAn3);*/
                Map<String, Object> htmlParamAn = new HashMap<String, Object>();
                htmlParamAn.put("datagridId", "anDatagrid");
                htmlParamAn.put("datagridUrl", "platform/deptdocarrangeController/getRecycleAnTableList?nodeId=" + nodeId + "&anTableId=" + anId + "&sysId=" + sysId + " ");
                htmlParamAn.put("datagridToolbarId", "anRecycleToolBar");
                htmlParamAn.put("domainObjectParam", "deptdocarrange_deptdocarrangeRecycleIframe_anDatagrid"); // 模块名_jsp名_tableid
                // htmlParamAn.put("colList", colListAn); // 固定列参数
                htmlParamAn.put("tabColList", listCloumDatas); // 对应显示字段
                String anMDatagridHtml = this.billDefineDynamicService.getDatagridHtml(htmlParamAn);
                mav.addObject("anMDatagridHtml", anMDatagridHtml);

                /* TODO NO.4[更改详细列]去除全文改为题名查看详情 create by 赵晓龙 */
                List<Map<String, Object>> listCloumResultData = new ArrayList<>();
                for (Map<String, Object> map : fileTableList) {
                    String name = map.get("COL_NAME") == null ? "" : map.get("COL_NAME").toString();
                    if (name.equals("TM")) {
                        map.put("FORMATTER", "formatDetailText");
                    }
                    listCloumResultData.add(map);
                }
                // 绘制案卷目录table(从)
               /* Map<String, Object> colMapAnC1 = new HashMap<String, Object>();
                colMapAnC1.put("COL_NAME_EN", "ATTACH_SIZE");
                colMapAnC1.put("FORMATTER_NAME", "formatAllText");
                Map<String, Object> colMapAnC3 = new HashMap<String, Object>();
                colMapAnC3.put("COL_NAME_EN", "3");
                colMapAnC3.put("FORMATTER_NAME", "formatDetailText");
                if ("zh_CN".equals(sessionLanguageCode)) {
                    colMapAnC1.put("COL_NAME_CN", "全文");
                    colMapAnC3.put("COL_NAME_CN", "详细");
                } else {
                    colMapAnC1.put("COL_NAME_CN", "Full Text");
                    colMapAnC3.put("COL_NAME_CN", "Detail");
                }
                List<Map<String, Object>> colListAnC = new ArrayList<Map<String, Object>>();
                colListAnC.add(colMapAnC1);
                colListAnC.add(colMapAnC3);*/
                Map<String, Object> htmlParamAnC = new HashMap<String, Object>();
                htmlParamAnC.put("datagridId", "childDatagrid");
                htmlParamAnC.put("datagridUrl", "");
                htmlParamAnC.put("datagridToolbarId", "childFileToolbar");
                htmlParamAnC.put("domainObjectParam", "deptdocarrange_deptdocarrangeRecycleIframe_childDatagrid"); // 模块名_jsp名_tableid
                // htmlParamAnC.put("colList", colListAnC);
                htmlParamAnC.put("tabColList", fileTableList);
                String anCDatagridHtml = this.billDefineDynamicService.getDatagridHtml(htmlParamAnC);
                mav.addObject("anCDatagridHtml", anCDatagridHtml);

                mav.addObject("anMapCode", anMapCode);
                mav.addObject("anDeptCols", anDeptCols);
                mav.addObject("anTableId", anId);
                mav.addObject("anSearchList", anSearchList);
                mav.addObject("anTableList", anTableList);
                mav.addObject("anTableListSize", anTableList.size());
            }
            mav.addObject("nodeId", nodeId);
            mav.addObject("sysId", sysId);
            mav.addObject("allList", allList);
            mav.addObject("sysFlag", this.sysFlag);
            mav.addObject("attachRecordIdKey", "ID");
            mav.addObject("attachNodeIdKey", "NODE_ID");
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeRecycleIframe");
            mav.addObject("result", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("result", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 获得文件目录列表回收站数据集合
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getRecycleFileTableList")
    public ModelAndView getRecycleFileTableList(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String nodeId = request.getParameter("nodeId");
        String fileTableId = request.getParameter("fileTableId");
        String json = request.getParameter("param");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String pageNo = request.getParameter("page");
        String pageSize = request.getParameter("rows");
        StringBuffer sb = new StringBuffer();
        Map<String, Object> searchMap = new HashMap<String, Object>();
        if (null != json && !"".equals(json)) {
            searchMap = JsonUtils.newInstance().Json2Bean2DataGrid(json, Map.class);
        }
        Iterator<String> searchList = searchMap.keySet().iterator();
        while (searchList.hasNext()) {
            String searchName = searchList.next();
            String searchValue = (String) searchMap.get(searchName);
            String searchType = searchName.substring(0, 4);
            if ("SELE".equals(searchType)) {
                if (null != searchValue && !"".equals(searchValue)) {
                    sb.append(" and ");
                    sb.append(searchName.substring(5));
                    sb.append(" = '");
                    sb.append(searchValue);
                    sb.append("' ");
                }
            } else if ("USER".equals(searchType) || "DEPT".equals(searchType)) {
                int index = searchName.lastIndexOf("_");
                if (null != searchValue && !"".equals(searchValue)) {
                    sb.append(" and ");
                    sb.append(searchName.substring(5, index));
                    sb.append(" = '");
                    sb.append(searchValue);
                    sb.append("' ");
                }
            } else if ("INPU".equals(searchType)) {
                if (null != searchValue && !"".equals(searchValue)) {
                    sb.append(" and ");
                    sb.append(searchName.substring(5));
                    sb.append(" LIKE '%");
                    sb.append(searchValue);
                    sb.append("%' ");
                }
            } else if ("DATE".equals(searchType)) {
                if (null != searchValue && !"".equals(searchValue)) {
                    sb.append(" and to_char(");
                    sb.append(searchName.substring(5));
                    sb.append(",'yyyy-mm-dd') = '");
                    sb.append(searchValue);
                    sb.append("' ");
                }
            } else {
                if (null != searchValue && !"".equals(searchValue)) {
                    sb.append(" and ");
                    sb.append(searchName.substring(5));
                    sb.append(" LIKE '%");
                    sb.append(searchValue);
                    sb.append("%' ");
                }
            }
        }
        Map<String, Object> listParam = new HashMap<String, Object>();
        sb.append(" and ARCHIVE_STATUS = '2' and NODE_ID = '" + nodeId + "' AND (PARENT_ID IS NULL OR PARENT_ID = '')");
        // String userId = SessionHelper.getLoginSysUserId(request);
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("userSecretLevel", SessionHelper.getLoginSysUser(request).getSecretLevel());
        Map<String, String> map = this.userAuthIntfsService.getUserAuthDatasByIntfs(orgId, deptId, sysId, "3", SessionHelper.getLoginSysUserId(request), "LANTOP_AUTH_SERVER_USERSET", nodeId, fileTableId, "", param);
        String authSql = map.get("SQL");
        sb.append(authSql);
        sb.append(" AND ARCHIVE_SHARE_STATUS = '2'");

        List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, fileTableId, pageNo, pageSize, sb.toString(), listParam);
        String total = "0";
        // this.getAttachNum(list);

        // 判断是否存在库房组件接口
        if (null != storeroommanagerIntfsService) {
            // 数据ids
            String positionIds = "";
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> m = list.get(i);
                positionIds += (String) m.get("ID");
                if (i != list.size() - 1) {
                    positionIds += ",";
                }
            }
            Map<String, Object> positionMap = new HashMap<String, Object>();
            positionMap.put("IDS", positionIds);
            // 通过数据id获取存放位置map
            Map<String, Object> storeMap = this.storeroommanagerIntfsService.getStoreRoomPositionMessageByRecordIdsByIntfs(positionMap);
            // 通过数据id获取存放位置,并添加到存放位置字段中
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> m = list.get(i);
                String id = m.get("ID") + "";
                String position = storeMap.get(id) + "";
                if ("null".equals(position)) {
                    position = "";
                }
                m.put("ARCHIVE_POSITION", position);
            }
        }

        if (null != list && list.size() > 0) {
            total = list.get(0).get("ROW_COUNT") + "";
        }
        mav.addObject("total", total);
        mav.addObject("rows", list);
        return mav;
    }

    /**
     * 获得文件目录列表回收站数据集合
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getRecycleAnTableList")
    public ModelAndView getRecycleAnTableList(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String nodeId = request.getParameter("nodeId");
        String anTableId = request.getParameter("anTableId");
        String json = request.getParameter("param");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String pageNo = request.getParameter("page");
        String pageSize = request.getParameter("rows");
        StringBuffer sb = new StringBuffer();
        Map<String, Object> searchMap = new HashMap<String, Object>();
        Map<String, Object> listParam = new HashMap<String, Object>();
        if (null != json && !"".equals(json)) {
            searchMap = JsonUtils.newInstance().Json2Bean2DataGrid(json, Map.class);
        }
        Iterator<String> searchList = searchMap.keySet().iterator();
        while (searchList.hasNext()) {
            String searchName = searchList.next();
            String searchValue = (String) searchMap.get(searchName);
            String searchType = searchName.substring(0, 4);
            if ("SELE".equals(searchType)) {
                if (null != searchValue && !"".equals(searchValue)) {
                    sb.append(" and ");
                    sb.append(searchName.substring(5));
                    sb.append(" = '");
                    sb.append(searchValue);
                    sb.append("' ");
                }
            } else if ("USER".equals(searchType) || "DEPT".equals(searchType)) {
                int index = searchName.lastIndexOf("_");
                if (null != searchValue && !"".equals(searchValue)) {
                    sb.append(" and ");
                    sb.append(searchName.substring(5, index));
                    sb.append(" = '");
                    sb.append(searchValue);
                    sb.append("' ");
                }
            } else if ("INPU".equals(searchType)) {
                if (null != searchValue && !"".equals(searchValue)) {
                    sb.append(" and ");
                    sb.append(searchName.substring(5));
                    sb.append(" LIKE '%");
                    sb.append(searchValue);
                    sb.append("%' ");
                }
            } else if ("DATE".equals(searchType)) {
                if (null != searchValue && !"".equals(searchValue)) {
                    sb.append(" and to_char(");
                    sb.append(searchName.substring(5));
                    sb.append(",'yyyy-mm-dd') = '");
                    sb.append(searchValue);
                    sb.append("' ");
                }
            } else {
                if (null != searchValue && !"".equals(searchValue)) {
                    sb.append(" and ");
                    sb.append(searchName.substring(5));
                    sb.append(" LIKE '%");
                    sb.append(searchValue);
                    sb.append("%' ");
                }
            }
        }
        sb.append(" and ARCHIVE_STATUS = '2' and NODE_ID = '" + nodeId + "'");

        Map<String, Object> param = new HashMap<String, Object>();
        param.put("userSecretLevel", SessionHelper.getLoginSysUser(request).getSecretLevel());
        Map<String, String> map = this.userAuthIntfsService.getUserAuthDatasByIntfs(orgId, deptId, sysId, "3", SessionHelper.getLoginSysUserId(request), "LANTOP_AUTH_SERVER_USERSET", nodeId, anTableId, "", param);
        String authSql = map.get("SQL");
        sb.append(authSql);
        // String userId = SessionHelper.getLoginSysUserId(request);
        sb.append(" AND ARCHIVE_SHARE_STATUS = '2'");
        List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, anTableId, pageNo, pageSize, sb.toString(), listParam);
        String total = "0";
        // this.getAttachNum(list);

        // 判断是否存在库房组件接口
        if (null != storeroommanagerIntfsService) {
            // 数据ids
            String positionIds = "";
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> m = list.get(i);
                positionIds += (String) m.get("ID");
                if (i != list.size() - 1) {
                    positionIds += ",";
                }
            }
            Map<String, Object> positionMap = new HashMap<String, Object>();
            positionMap.put("IDS", positionIds);
            // 通过数据id获取存放位置map
            Map<String, Object> storeMap = this.storeroommanagerIntfsService.getStoreRoomPositionMessageByRecordIdsByIntfs(positionMap);
            // 通过数据id获取存放位置,并添加到存放位置字段中
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> m = list.get(i);
                String id = m.get("ID") + "";
                String position = storeMap.get(id) + "";
                if ("null".equals(position)) {
                    position = "";
                }
                m.put("ARCHIVE_POSITION", position);
            }
        }

        if (null != list && list.size() > 0) {
            total = list.get(0).get("ROW_COUNT") + "";
        }
        mav.addObject("total", total);
        mav.addObject("rows", list);
        return mav;
    }

    /**
     * 回收站还原操作/清空回收站操作
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/updateRecycle")
    public ModelAndView updateRecycle(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String nodeId = request.getParameter("nodeId");
        String ids = request.getParameter("ids");
        String table = request.getParameter("table");
        String tableId = "";
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String anTableId = request.getParameter("anTableId");
        String parentId = request.getParameter("parentId");
        Map<String, Object> listParam = new HashMap<String, Object>();
        try {
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            // 所选节点对应物理表信息
            List<Map<String, Object>> allList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "");
            if (allList.size() == 1) {
                // 文件目录物理表
                List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "1");
                Map<String, Object> fileMap = fileList.get(0);
                tableId = fileMap.get("ID").toString();
            }
            if (allList.size() >= 2) {
                if (table.equals("file")) {
                    // 文件目录物理表
                    List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "2");
                    Map<String, Object> fileMap = fileList.get(0);
                    tableId = fileMap.get("ID").toString();
                } else {
                    // 案卷目录物理表
                    List<Map<String, Object>> anList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "1");
                    Map<String, Object> anMap = anList.get(0);
                    tableId = anMap.get("ID").toString();
                    // 文件目录物理表
                    List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "2");
                    Map<String, Object> fileMap = fileList.get(0);
                    String fileTableId = fileMap.get("ID").toString();
                    String fileIds = "";
                    String[] anIds = ids.split(";");
                    Map<String, Object> param = new HashMap<String, Object>();
                    param.put("modleName", modleName);
                    for (int i = 0; i < anIds.length; i++) {
                        String sql = " AND PARENT_ID = '" + anIds[i] + "'";
                        List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, fileTableId, "1", "100", sql, listParam);
                        param.put("ajDataId", anIds[i]);
                        for (int j = 0; j < list.size(); j++) {
                            Map<String, Object> map = list.get(j);
                            String id = map.get("ID").toString();
                            fileIds += id;
                            if (j != list.size() - 1) {
                                fileIds += ";";
                            }
                        }
                        Map<String, Object> mp = new HashMap<String, Object>();
                        mp.put("ARCHIVE_STATUS", 1);
                        this.billDefineManagerIntfsService.updateRecordByDataIdsWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, fileTableId, mp, fileIds, param);
                    }

                }
            }
            Map<String, Object> mapObj = new HashMap<String, Object>();
            mapObj.put("ARCHIVE_STATUS", "0");
            if (table.equals("file")) {
                mapObj.put("PARENT_ID", "");
            }
            // 获得选择撤件的最小卷内序号
            String newNumber = "0";
            // String copyNum = "0";
            // String pageNum = "0";
            if (null != anTableId && !"".equals(anTableId) && null != parentId && !"".equals(parentId)) {
                List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, anTableId, "1", "100", " AND ID = '" + parentId + "'", listParam);
                if (list.size() > 0) {
                    // Map<String, Object> resultMap = list.get(0);
                    // String resultCopy = (String)resultMap.get("ARCHIVE_COPY_NUM");
                    // String resultPage = (String)resultMap.get("ARCHIVE_PAGE_NUM");
                    String[] fileIds = ids.split(";");
                    String sql = " AND ID IN (";
                    for (int i = 0; i < fileIds.length; i++) {
                        sql += "'" + fileIds[i] + "',";
                    }
                    sql = sql.substring(0, sql.length() - 1) + ")";
                    sql += " AND PARENT_ID = '" + parentId + "'";
                    // 获得最小卷内序号
                    Object obj = this.billDefineManagerIntfsService.getOperationTableColDataByIntfs(tableId, sql, "ARCHIVE_IN_NUM", orgId, deptId, sysId, "MIN");
                    if (null != obj) {
                        newNumber = obj.toString();
                    }
                    // //获得份数和
                    // Object copyObj = this.billDefineManagerIntfsService.getOperationTableColDataByIntfs(tableId, sql, "ARCHIVE_COPY_NUM", orgId, deptId, sysId, "SUM");
                    // if (null != copyObj) {
                    // copyNum = copyObj.toString();
                    // }
                    // //获得页数和
                    // Object pageObj = this.billDefineManagerIntfsService.getOperationTableColDataByIntfs(tableId, sql, "ARCHIVE_PAGE_NUM", orgId, deptId, sysId, "SUM");
                    // if (null != pageObj) {
                    // pageNum = pageObj.toString();
                    // }
                    // Map<String, Object> updateMap = new HashMap<String, Object>();
                    // //案卷份数
                    // int copy = 0;
                    // //案卷页数
                    // int page = 0;
                    // //所选文件份数
                    // int fileCopy = 0;
                    // //所选文件页数
                    // int filePage = 0;
                    // if (null != resultCopy && !"".equals(resultCopy)) {
                    // copy = Integer.valueOf(resultCopy);
                    // }
                    // if (null != resultPage && !"".equals(resultPage)) {
                    // page = Integer.valueOf(resultPage);
                    // }
                    // if (null != copyNum && !"".equals(copyNum)) {
                    // fileCopy = Integer.valueOf(copyNum);
                    // }
                    // if (null != pageNum && !"".equals(pageNum)) {
                    // filePage = Integer.valueOf(pageNum);
                    // }
                    // if (copy >= fileCopy) {
                    // updateMap.put("ARCHIVE_COPY_NUM", copy - fileCopy);
                    // } else {
                    // updateMap.put("ARCHIVE_COPY_NUM", 0);
                    // }
                    // if (page >= filePage) {
                    // updateMap.put("ARCHIVE_PAGE_NUM", page - filePage);
                    // } else {
                    // updateMap.put("ARCHIVE_PAGE_NUM", 0);
                    // }
                    this.updateFileDataByAnDataIdByChe(orgId, deptId, sysId, tableId, nodeId, parentId, newNumber, modleName);
                    // this.billDefineManagerIntfsService.updateRecordByDataIdByIntfs(orgId, deptId, sysId, nodeId, anTableId, updateMap, parentId);
                }
            }
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("ajDataId", parentId);
            param.put("modleName", modleName);
            // this.billDefineManagerIntfsService.updateRecordByDataIdsByIntfs(orgId, deptId, sysId, nodeId, tableId, mapObj, ids);
            this.billDefineManagerIntfsService.updateRecordByDataIdsWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, tableId, mapObj, ids, param);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 回收站彻底删除数据方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/deleteDatas")
    public ModelAndView deleteDatas(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String menuCode = request.getParameter("menuCode");
        String table = request.getParameter("table");
        String ids = request.getParameter("ids");
        String nodeId = request.getParameter("nodeId");
        String tableId = "";
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String anTableId = request.getParameter("anTableId");
        String parentId = request.getParameter("parentId");
        Map<String, Object> listParam = new HashMap<String, Object>();
        try {
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            // 所选节点对应物理表信息
            List<Map<String, Object>> allList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "");
            if (allList.size() == 1) {
                if (table.equals("file")) {
                    // 文件目录物理表
                    List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "1");
                    Map<String, Object> fileMap = fileList.get(0);
                    tableId = fileMap.get("ID").toString();
                }
            }
            if (allList.size() >= 2) {
                if (table.equals("file")) {
                    // 文件目录物理表
                    List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "2");
                    Map<String, Object> fileMap = fileList.get(0);
                    tableId = fileMap.get("ID").toString();
                } else {
                    // 案卷目录物理表
                    List<Map<String, Object>> anList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "1");
                    Map<String, Object> anMap = anList.get(0);
                    tableId = anMap.get("ID").toString();
                }
                if (table.equals("an")) {
                    // 文件目录物理表
                    List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "2");
                    Map<String, Object> fileMap = fileList.get(0);
                    String fileTableId = fileMap.get("ID").toString();
                    String fileIds = "";
                    String[] anIds = ids.split(";");
                    for (int i = 0; i < anIds.length; i++) {
                        String sql = " AND PARENT_ID = '" + anIds[i] + "'";
                        List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, fileTableId, "1", "100", sql, listParam);
                        for (int j = 0; j < list.size(); j++) {
                            Map<String, Object> map = list.get(j);
                            String id = map.get("ID").toString();
                            fileIds += id;
                            if (j != list.size() - 1) {
                                fileIds += ";";
                            }
                        }
                    }
                    Map<String, Object> paramObj = new HashMap<String, Object>();
                    paramObj.put("modleName", modleName);
                    this.billDefineManagerIntfsService.deleteRecordByDataIdsByIntfs(orgId, deptId, sysId, nodeId, fileTableId, fileIds, paramObj);
                    String[] fileIdsArray = fileIds.split(";");
                    List<String> fileIdsList = Arrays.asList(fileIdsArray);
                    this.billDefineManagerIntfsService.deleteAttachmentByDataIdsByIntfs(fileIdsList, sysId);
                }
            }
            // 获得选择撤件的最小卷内序号
            String newNumber = "0";
            String copyNum = "0";
            String pageNum = "0";
            if (null != anTableId && !"".equals(anTableId) && null != parentId && !"".equals(parentId)) {
                List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, anTableId, "1", "100", " AND ID = '" + parentId + "'", listParam);
                if (list.size() > 0) {
                    Map<String, Object> resultMap = list.get(0);
                    String resultCopy = (String) resultMap.get("ARCHIVE_COPY_NUM");
                    String resultPage = (String) resultMap.get("ARCHIVE_PAGE_NUM");
                    String[] fileIds = ids.split(";");
                    String sql = " AND ID IN (";
                    for (int i = 0; i < fileIds.length; i++) {
                        sql += "'" + fileIds[i] + "',";
                    }
                    sql = sql.substring(0, sql.length() - 1) + ")";
                    sql += " AND PARENT_ID = '" + parentId + "'";
                    // 获得最小卷内序号
                    Object obj = this.billDefineManagerIntfsService.getOperationTableColDataByIntfs(tableId, sql, "ARCHIVE_IN_NUM", orgId, deptId, sysId, "MIN");
                    if (null != obj) {
                        newNumber = obj.toString();
                    }
                    // 获得份数和
                    Object copyObj = this.billDefineManagerIntfsService.getOperationTableColDataByIntfs(tableId, sql, "ARCHIVE_COPY_NUM", orgId, deptId, sysId, "SUM");
                    if (null != copyObj) {
                        copyNum = copyObj.toString();
                    }
                    // 获得页数和
                    Object pageObj = this.billDefineManagerIntfsService.getOperationTableColDataByIntfs(tableId, sql, "ARCHIVE_PAGE_NUM", orgId, deptId, sysId, "SUM");
                    if (null != pageObj) {
                        pageNum = pageObj.toString();
                    }
                    Map<String, Object> updateMap = new HashMap<String, Object>();
                    // 案卷份数
                    int copy = 0;
                    // 案卷页数
                    int page = 0;
                    // 所选文件份数
                    int fileCopy = 0;
                    // 所选文件页数
                    int filePage = 0;
                    if (null != resultCopy && !"".equals(resultCopy)) {
                        copy = Integer.valueOf(resultCopy);
                    }
                    if (null != resultPage && !"".equals(resultPage)) {
                        page = Integer.valueOf(resultPage);
                    }
                    if (null != copyNum && !"".equals(copyNum)) {
                        fileCopy = Integer.valueOf(copyNum);
                    }
                    if (null != pageNum && !"".equals(pageNum)) {
                        filePage = Integer.valueOf(pageNum);
                    }
                    if (copy >= fileCopy) {
                        updateMap.put("ARCHIVE_COPY_NUM", copy - fileCopy);
                    } else {
                        updateMap.put("ARCHIVE_COPY_NUM", "");
                    }
                    if (page >= filePage) {
                        updateMap.put("ARCHIVE_PAGE_NUM", page - filePage);
                    } else {
                        updateMap.put("ARCHIVE_PAGE_NUM", "");
                    }
                    this.updateFileDataByAnDataIdByChe(orgId, deptId, sysId, tableId, nodeId, parentId, newNumber, modleName);
                    Map<String, Object> param = new HashMap<String, Object>();
                    param.put("ajDataId", "");
                    param.put("modleName", modleName);
                    this.billDefineManagerIntfsService.updateRecordByDataIdWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, anTableId, updateMap, parentId, param);
                }
            }
            Map<String, Object> paramObj = new HashMap<String, Object>();
            paramObj.put("modleName", modleName);
            this.billDefineManagerIntfsService.deleteRecordByDataIdsByIntfs(orgId, deptId, sysId, nodeId, tableId, ids, paramObj);
            String[] idsArray = ids.split(";");
            List<String> idsList = Arrays.asList(idsArray);
            this.billDefineManagerIntfsService.deleteAttachmentByDataIdsByIntfs(idsList, sysId);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 初始化目标档案库树结构
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/initTargetArchiveTree")
    public ModelAndView initTargetArchiveTree(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String tableId = request.getParameter("tableId");
        String formId = request.getParameter("formId");
        List<TreeNode> nodes = new ArrayList<TreeNode>();
        try {
            if (null == tableId || "".equals(tableId)) {
                LantopSubmit ls = this.deptdocarrangeService.getSubmitById(formId);
                if (null != ls) {
                    tableId = ls.getArchiveTableId();
                    List<Map<String, Object>> publicColList = commTableManagerIntfsService.getCbbTableAndColumnsByTabNameByIntfs(ls.getOrgId(), ls.getDeptId(), ls.getSysId(), "LANTOP_ARC_BOX_CATA"); // 公共字段
                    // 获得盒目录tableId
                    String boxTableId = "";
                    if (publicColList.size() > 0) {
                        Map<String, Object> boxMap = publicColList.get(0);
                        boxTableId = (String) boxMap.get("TABLE_ID");
                    }
                    if (boxTableId.equals(tableId)) {
                        List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(ls.getOrgId(), ls.getDeptId(), ls.getSysId(), ls.getArchiveNodeId(), "1");
                        if (fileList.size() > 0) {
                            Map<String, Object> map = fileList.get(0);
                            tableId = (String) map.get("ID");
                        }
                    }
                }
            }
            nodes = this.deptdocarrangeService.getTargetDatasByTableId(tableId);
            // nodes = this.archiveClassManagerIntfsService.getArchiveClassTreeNodeToDataNodeInfoByIntfs(orgId, deptId);
            mav.addObject("data", nodes);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 判断是否定义过对应字段设置信息
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getIsExists")
    public ModelAndView getIsExists(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String id = request.getParameter("id");
        String tableId = request.getParameter("tableId");
        if (null == tableId || "".equals(tableId) || "null".equals(tableId)) {
            tableId = this.deptdocarrangeService.getTableIdByFormId(id);
        }
        String classId = request.getParameter("classId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        if (null == sysId || "".equals(sysId) || "null".equals(sysId)) {
            sysId = "LANTOP";
        }
        sysId = this.commSysInfoIntfsService.getSysIdByIntfs(sysId);
        try {
            boolean isExists = this.fieldMapSetIntfsService.isExistsFieldMapSetByIntfs(orgId, deptId, sysId, tableId, classId);
            mav.addObject("isExists", isExists);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 跳转添加归档数据页面
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/toAddSubmitJsp")
    public ModelAndView toAddSubmitJsp(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String dialogId = request.getParameter("dialogId");
        // 选择方式 select 所选; all 全部
        String type = request.getParameter("type");
        String tableId = request.getParameter("tableId");
        String fileTableId = request.getParameter("fileTableId");
        String nodeId = request.getParameter("nodeId");
        String table = request.getParameter("table");
        String sysId = request.getParameter("sysId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String userId = SessionHelper.getLoginSysUserId(request);
        try {
            if (null != table && !"".equals(table) && "an".equals(table)) {
                mav.addObject("isAn", true);
            } else {
                mav.addObject("isAn", false);
            }
            mav.addObject("fileTableId", fileTableId);
            mav.addObject("type", type);
            mav.addObject("dialogId", dialogId);
            mav.addObject("tableId", tableId);
            mav.addObject("nodeId", nodeId);
            mav.addObject("table", table);
            mav.addObject("sysId", sysId);
            List<Map<String, Object>> fondsList = this.cbbFondsDbIntfsService.getCbbFondsDbInfoByIntfs(orgId, deptId, sysId, orgId);
            String fondsNumber = "";
            if (fondsList.size() > 0) {
                Map<String, Object> fondsMap = fondsList.get(0);
                fondsNumber = (String) fondsMap.get("ORG_CODE");
            }
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("currentUserId", userId);
            param.put("currentDeptId", deptId);
            param.put("currentOrgCode", fondsNumber);
            param.put("nodeId", nodeId);
            Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
            param.put("languageCode", sessionLanguageCode);
            String userName = userLoader.getSysUserById(userId).getName();
            String deptName = deptLoader.getSysDeptTl(deptId, "zh_CN").getDeptName();
            Date date = new Date(System.currentTimeMillis());
            String submitTitle = userName + "的文件归档";
            // 文件动态显示字段集合
            List<Map<String, Object>> fileTableList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, tableId, "2", "", param);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String newDate = sdf.format(date);
            mav.addObject("nowDate", newDate);
            mav.addObject("fondsNumber", fondsNumber);
            mav.addObject("fileSize", fileTableList.size());
            mav.addObject("fileTableList", fileTableList);
            mav.addObject("submitTitle", submitTitle);
            mav.addObject("userId", userId);
            mav.addObject("userName", userName);
            mav.addObject("deptId", deptId);
            mav.addObject("deptName", deptName);
            mav.addObject("sysFlag", this.sysFlag);
            mav.addObject("flag", OpResult.success.ordinal());
            mav.addObject("result", true);
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeFileSubmitAdd");
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 获得选中数据
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getDatasByIds")
    public ModelAndView getDatasByIds(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        // 所选/全部
        String type = request.getParameter("type");
        String sysId = request.getParameter("sysId");
        String tableId = request.getParameter("tableId");
        String ids = request.getParameter("ids");
        String condition = request.getParameter("condition");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String pageNo = request.getParameter("page");
        String pageSize = request.getParameter("rows");
        String notInId = request.getParameter("notInId");
        Map<String, Object> listParam = new HashMap<String, Object>();
        try {
            String sql = "";
            if ("select".equals(type)) {
                String[] idsArray = null;
                if (null != ids && !"".equals(ids)) {
                    idsArray = ids.split(";");
                }
                if (null != ids) {
                    sql = " and ID IN (";
                    for (int i = 0; i < idsArray.length; i++) {
                        sql += "'" + idsArray[i] + "',";
                    }
                    sql = sql.substring(0, sql.length() - 1);
                    sql += ")";
                }
            } else {
                // 获取到列表查询条件后增加未归档过滤和未提交流程过滤
                sql += " AND " + condition + " AND (ARCHIVE_STATUS = '1' OR ARCHIVE_STATUS IS NULL) AND (ARCHIVE_FLOW_STATUS = '1' OR ARCHIVE_FLOW_STATUS IS NULL) ";
            }
            if (null != notInId && !"".equals(notInId)) {
                sql += " AND ID NOT IN (";
                String[] notIds = notInId.split(";");
                for (int i = 0; i < notIds.length; i++) {
                    sql += "'" + notIds[i] + "'";
                    if (i != notIds.length - 1) {
                        sql += ",";
                    }
                }
                sql += ")";
            }
            List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, tableId, pageNo, pageSize, sql, listParam);
            // this.getAttachNum(list);

            // 判断是否存在库房组件接口
            if (null != storeroommanagerIntfsService) {
                // 数据ids
                String positionIds = "";
                for (int i = 0; i < list.size(); i++) {
                    Map<String, Object> m = list.get(i);
                    positionIds += (String) m.get("ID");
                    if (i != list.size() - 1) {
                        positionIds += ",";
                    }
                }
                Map<String, Object> positionMap = new HashMap<String, Object>();
                positionMap.put("IDS", positionIds);
                // 通过数据id获取存放位置map
                Map<String, Object> storeMap = this.storeroommanagerIntfsService.getStoreRoomPositionMessageByRecordIdsByIntfs(positionMap);
                // 通过数据id获取存放位置,并添加到存放位置字段中
                for (int i = 0; i < list.size(); i++) {
                    Map<String, Object> m = list.get(i);
                    String id = m.get("ID") + "";
                    String position = storeMap.get(id) + "";
                    if ("null".equals(position)) {
                        position = "";
                    }
                    m.put("ARCHIVE_POSITION", position);
                }
            }

            String total = "0";
            if (null != list && list.size() > 0) {
                total = list.get(0).get("ROW_COUNT") + "";
            }
            mav.addObject("total", total);
            mav.addObject("rows", list);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 归档-保存方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/saveSubmitData")
    public ModelAndView saveSubmitData(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String table = request.getParameter("table");
        String nodeId = request.getParameter("nodeId");
        String idsAll = request.getParameter("ids");
        // 所选/全部
        String type = request.getParameter("type");
        String condition = request.getParameter("condition");
        String tableId = request.getParameter("tableId");
        String processDefId = request.getParameter("processDefId");
        //全宗号不从前台获取
//		String fondsNumber = request.getParameter("fondsNumber");
        String formCode = request.getParameter("formCode");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String tm = request.getParameter("tm");
        String userId = SessionHelper.getLoginSysUserId(request);
        Map<String, Object> listParam = new HashMap<String, Object>();
        LantopSubmit ls = new LantopSubmit();

        DateUtilNew dateUtilNew = new DateUtilNew();
        //SanXia create An start 因页面修改，原有的datas 没有了。submitTitle 直接获取

        //     修改于：2020-01-09
        //     文件归档审批单标题优化
        //    (1)文书类：集团办公室2019年度文书类档案（第一批）(*按照年度自动生成序号、件级)（例：节点名称+年度+"年度文书类档案"+序号）
        //    (2)招采类：***（项目名称）招标采购档案(只管接收过来的招采的数据，包括招标与非招)
        //    (3)合同类：***（项目名称）合同签订档案(只管接收过来的合同数据)
        String submitTitle = "";
        String typenew = "1";
        //判断是否为档案管理-文书类节点   2020-12-03   流程标题规则改变
        /*String clericalClassName = archiveClassManagerIntfsService.isClericalClassTreeNode(nodeId, orgId, tableId);
        if (StringUtils.isEmpty(clericalClassName)){
            //判断数据来源系统
            Map<String, String> filesMap = deptdocarrangeService.judgeDataSource(idsAll, tableId);
            String dataType = filesMap.get("type");
            if("1".equals(dataType)){
                //招标采购类档案，审批序号存0，为了查询普通类归档审批最大的序号（普通类查询最大序号要排除招标、合同、文书类数据）
                ls.setAttribute04("0");
                submitTitle = filesMap.get("TM");
            }else if("2".equals(dataType)){
                //合同签订档案，审批序号存0，为了查询普通类归档审批最大的序号（普通类查询最大序号要排除招标、合同、文书类数据）
                ls.setAttribute04("0");
                submitTitle = filesMap.get("TM");
            }else{//普通归档审批名称序号生成规则
                String userName = userLoader.getSysUserById(userId).getName();
                //SanXia create By An start 题名由加时间戳改为添加年和流水号
                List<Map<String, Object>> mapList = deptdocarrangeService.getMAXNUMById(sysId, orgId, deptId, userId, typenew);
                String nameH = mapList.get(0).get("TNUM") != null ? (Integer.valueOf(mapList.get(0).get("TNUM").toString()) + 1) + "" : dateUtilNew.getYearDate() + "0001";
                submitTitle = userName + "的文件归档" + nameH;
            }
        }else{
            List<Map<String, Object>> mapMaxOrder = deptdocarrangeService.getMAXORDERById(sysId, orgId, deptId, userId, typenew);
            String order = mapMaxOrder.get(0).get("TNUM") != null && Integer.valueOf(mapMaxOrder.get(0).get("TNUM").toString()) > 0 ? (Integer.valueOf(mapMaxOrder.get(0).get("TNUM").toString()) + 1) + "" : "1";
            ls.setAttribute04(order);
            order = ChineseNumberUtil.cvt(Integer.valueOf(order), true);
            submitTitle = clericalClassName+dateUtilNew.getYearDate()+"年度文书类档案"+"(第"+order+"批)";
        }*/
        submitTitle = tm;
        //SanXia creaete by an end
        //获得全宗号
        List<Map<String, Object>> fondsList = this.cbbFondsDbIntfsService.getCbbFondsDbInfoByIntfs(orgId, deptId, sysId, orgId);
        String fondsNumber = "";
        if (fondsList.size() > 0) {
            Map<String, Object> fondsMap = fondsList.get(0);
            fondsNumber = (String) fondsMap.get("ORG_CODE");
        }

//		LantopSubmit ls = JsonUtils.newInstance().Json2Bean2Form(request.getParameter("datas"), LantopSubmit.class);
        ls.setSubmitTitile(submitTitle);
        //区别入库和跨全宗移交
        ls.setAttribute03("1");
        //SanXia create An end

        try {
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            // 所选节点对应物理表信息
            List<Map<String, Object>> allList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "");
            String tableName = "";
            String tableTitle = "";
            if (allList.size() == 1) {
                // 文件目录标签页物理表信息
                List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "1");
                Map<String, Object> fileMap = fileList.get(0);
                tableName = fileMap.get("TABLE_NAME").toString();
                tableTitle = fileMap.get("TABLE_TITLE").toString();
            }
            if (allList.size() >= 2) {
                if (table.equals("file")) {
                    // 文件目录标签页物理表信息
                    List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "2");
                    Map<String, Object> fileMap = fileList.get(0);
                    tableName = fileMap.get("TABLE_NAME").toString();
                    tableTitle = fileMap.get("TABLE_TITLE").toString();
                } else {
                    // 案卷目录标签页物理表信息
                    List<Map<String, Object>> anList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "1");
                    Map<String, Object> anMap = anList.get(0);
                    tableName = anMap.get("TABLE_NAME").toString();
                    tableTitle = anMap.get("TABLE_TITLE").toString();
                }
            }
            ls.setOrgId(orgId);
            ls.setDeptId(deptId);
            ls.setSysId(sysId);
            ls.setArchiveTableId(tableId);
            ls.setArchiveNodeId(nodeId);
            ls.setFondsNumber(fondsNumber);
            // ls.setApplayTime(new Date(System.currentTimeMillis()));
            ls.setSubmitUserId(userId);
            ls.setSubmitDeptId(deptId);
            Map<String, Object> parameter = new HashMap<String, Object>();
            String patha = request.getSession().getServletContext().getRealPath("/");
            parameter.put("path", patha);
            parameter.put("processDefId", processDefId);
            parameter.put("formCode", formCode);
            parameter.put("userId", SessionHelper.getLoginSysUserId(request));
            parameter.put("deptId", deptId);
            parameter.put("nodeId",nodeId);
            ls.setSubmitUserId(SessionHelper.getLoginSysUserId(request));
            ls.setSubmitDeptId(deptId);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH：mm：ss");
            ls.setApplayTime(sdf.parse(sdf.format(new Date(System.currentTimeMillis()))));
            // String submitDate = new Date(sdf.format(new Date(System.currentTimeMillis())));
            BeanProcess bp = this.deptdocarrangeService.saveSubmitData(ls, parameter);
            String id = bp.getFormId();
            String[] ids = null;
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("ajDataId", "");
            param.put("modleName", modleName);
            String idsString = "";
            if ("select".equals(type)) {
                ids = idsAll.split(";");
                idsString = idsAll;
            } else {
                List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, tableId, "", "", " AND " + condition, listParam);
                List<String> idList = new ArrayList<String>();
                for (int i = 0; i < list.size(); i++) {
                    Map<String, Object> map = list.get(i);
                    idList.add((String) map.get("ID"));
                    idsString += map.get("ID");
                    if (i != list.size() - 1) {
                        idsString += ";";
                    }
                }
                ids = idList.toArray(new String[idList.size()]);
            }
            for (int i = 0; i < ids.length; i++) {
                LantopSubmitItem lsi = new LantopSubmitItem();
                lsi.setArchiveRcdId(ids[i]);
                lsi.setArchiveTableId(tableId);
                lsi.setArchiveTableName(tableName);
                lsi.setArchiveTableTitle(tableTitle);
                lsi.setLantopSubmitId(id);
                lsi.setOrgId(orgId);
                lsi.setDeptId(deptId);
                lsi.setSysId(sysId);
                this.deptdocarrangeService.saveSubmitItemData(lsi);
            }
//            if (ids.length > 0) {
//                Map<String, Object> updateMap = new HashMap<String, Object>();
//                updateMap.put("ARCHIVE_FLOW_STATUS", "2");
//                this.billDefineManagerIntfsService.updateRecordByDataIdsWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, tableId, updateMap, idsString, param);
//            }
            String fileTableId = "";
            // 如果是归档案卷信息,则进行案卷信息对应文件信息的新增明细
            if (table.equals("an")) {
                // 文件目录标签页物理表信息
                List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "2");
                Map<String, Object> fileMap = fileList.get(0);
                fileTableId = fileMap.get("ID").toString();
            } else {
                // 文件目录标签页物理表信息
                List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "1");
                Map<String, Object> fileMap = fileList.get(0);
                fileTableId = fileMap.get("ID").toString();
            }
            String sql = " AND PARENT_ID IN (";
            for (int i = 0; i < ids.length; i++) {
                sql += "'" + ids[i] + "'";
                if (i != ids.length - 1) {
                    sql += ",";
                }
            }
            sql += ")";
            List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
            if (ids.length > 0 && table.equals("an")) {
                list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, fileTableId, "", "", sql, listParam);
                StringBuffer fileIds = new StringBuffer();
                for (int j = 0; j < list.size(); j++) {
                    Map<String, Object> map = list.get(j);
                    fileIds.append(map.get("ID").toString());
                    if (j != list.size() - 1) {
                        fileIds.append(";");
                    }
                }
                Map<String, Object> updateMap = new HashMap<String, Object>();
                updateMap.put("ARCHIVE_FLOW_STATUS", "2");
                if (fileIds.length() > 1) {
                    this.billDefineManagerIntfsService.updateRecordByDataIdsWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, fileTableId, updateMap, fileIds.toString(), param);
                }
            }
            // 写入代办
            Map<String, Object> map = new HashMap<String, Object>();
            //SanXia update by An  start 原有的为2，修改后改为7
            map.put("APPLY_TYPE", "7");
            //SanXia update by An end
            map.put("APPLY_TITLE", ls.getSubmitTitile());
            map.put("APPLY_USER_ID", ls.getSubmitUserId());
            map.put("APPLY_DEPT_ID", ls.getSubmitDeptId());
            map.put("FORM_ID", id);
            map.put("RECORD_DETAIL_URL", bp.getTaskUrl());
            map.put("TABLE_NAME", "LANTOP_SUBMIT");
            map.put("R_TABLE_NAME", "LANTOP_SUBMIT_ITEM");
            map.put("NODE_ID", nodeId);
            map.put("ENTRY_ID", bp.getProcessInstanceId());
            List<Map<String, Object>> undoList = new ArrayList<Map<String, Object>>();
            undoList.add(map);
            this.undoMessageManagerIntfsService.insertRecordByBatchApplyByIntfs(orgId, deptId, sysId, undoList);
            mav.addObject("sysId", sysId);
            mav.addObject("nodeId", nodeId);
            mav.addObject("tableId", tableId);
            mav.addObject("id", id);
            mav.addObject("bp", bp);
            mav.addObject("title", submitTitle);
            //编辑需要参数
            mav.addObject("share", request.getParameter("share"));
            mav.addObject("createdNum", request.getParameter("createdNum"));
            mav.addObject("isParent", request.getParameter("isParent"));
            mav.addObject("fileAllNode", request.getParameter("fileAllNode"));
            mav.addObject("showFileFlag", request.getParameter("showFileFlag"));
            mav.addObject("selectRecordId", request.getParameter("selectRecordId"));
            mav.addObject("parentNodeId", request.getParameter("parentNodeId"));
            mav.addObject("fileTypeFlag", request.getParameter("fileTypeFlag"));
            mav.addObject("pt", request.getParameter("pt"));
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 更新流程信息方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     */
    @RequestMapping("/updateSubmitData")
    public ModelAndView updateSubmitData(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        LantopSubmit ls = JsonUtils.newInstance().Json2Bean2Form(request.getParameter("datas"), LantopSubmit.class);
        try {
            this.deptdocarrangeService.updateSubmitData(ls);
            /*
             * List<Map<String, Object>> list = new ArrayList<Map<String,Object>>(); Map<String, Object> map = new HashMap<String, Object>(); map.put("FORM_ID", ls.getId());
             * map.put("APPLY_TITLE", ls.getSubmitTitile()); map.put("APPLY_USER_ID", ls.getSubmitUserId()); map.put("APPLY_DEPT_ID", ls.getSubmitDeptId()); list.add(map);
             * this.undoMessageManagerIntfsService.updateRecordByBatchApplyByIntfs(list);
             */
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 跳转submititem页面
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/toSubmitDetailItemJsp")
    public ModelAndView toSubmitDetailItemJsp(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String id = request.getParameter("id");
        String nodeId = "";
        String tableId = "";
        String dialogId = request.getParameter("dialogId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String userId = SessionHelper.getLoginSysUserId(request);
        String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
        SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
        String orgCode = so.getOrgCode();
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("currentUserId", userId);
        param.put("currentDeptId", deptId);
        param.put("currentOrgCode", orgCode);
        Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
        param.put("languageCode", sessionLanguageCode);
        if (null == sysId || "".equals(sysId) || "null".equals(sysId)) {
            sysId = "LANTOP";
        }
        sysId = this.commSysInfoIntfsService.getSysIdByIntfs(sysId);
        LantopSubmit ls = this.deptdocarrangeService.getSubmitById(id);
        nodeId = ls.getArchiveNodeId();
        tableId = ls.getArchiveTableId();
        List<Map<String, Object>> tableList = null;
        List<LantopSubmitItem> lsis = this.deptdocarrangeService.getSubmitItemBySid(id, tableId);
        boolean isAn = false;
        for (int i = 0; i < lsis.size(); i++) {
            String tableName = lsis.get(i).getArchiveTableName();
            tableName = tableName.substring(tableName.length() - 3, tableName.length());
            if ("AJJ".equals(tableName)) {
                tableId = lsis.get(0).getArchiveTableId();
                isAn = true;
            }
        }
        String fileTableId = "";
        if (isAn) {
            List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "2");
            Map<String, Object> fileMap = fileList.get(0);
            fileTableId = fileMap.get("ID").toString();
        } else {
            List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "1");
            Map<String, Object> fileMap = fileList.get(0);
            fileTableId = fileMap.get("ID").toString();
        }
        tableList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, tableId, "2", "", param);
        mav.addObject("isAn", isAn);
        mav.addObject("sysFlag", this.sysFlag);
        mav.addObject("id", id);
        mav.addObject("sysId", sysId);
        mav.addObject("nodeId", nodeId);
        mav.addObject("fileTableId", fileTableId);
        mav.addObject("tableId", tableId);
        mav.addObject("tableList", tableList);
        mav.addObject("tableListSize", tableList.size());
        mav.addObject("dialogId", dialogId);
        mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeFileSubmitDetailIframe");
        return mav;
    }

    /**
     * 获得归档文件级列表信息
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getSubmitFileTableList")
    public ModelAndView getSubmitFileTableList(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String dialogId = request.getParameter("dialogId");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String parentId = request.getParameter("parentId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String userId = SessionHelper.getLoginSysUserId(request);
        String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
        SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
        String orgCode = so.getOrgCode();
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("currentUserId", userId);
        param.put("currentDeptId", deptId);
        param.put("currentOrgCode", orgCode);
        Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
        param.put("languageCode", sessionLanguageCode);
        try {
            List<Map<String, Object>> tableList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, tableId, "2", "", param);
            mav.addObject("tableListSize", tableList.size());
            mav.addObject("tableList", tableList);
            mav.addObject("nodeId", nodeId);
            mav.addObject("tableId", tableId);
            mav.addObject("parentId", parentId);
            mav.addObject("sysId", sysId);
            mav.addObject("dialogId", dialogId);
            mav.addObject("flag", OpResult.success.ordinal());
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeFileSubmitFileDatas");
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 获得归档案卷级的文件级数据
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getSubmitFileDatasByParentId")
    public ModelAndView getSubmitFileDatasByParentId(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        String parentId = request.getParameter("parentId");
        String tableId = request.getParameter("tableId");
        String pageNo = request.getParameter("page");
        String pageSize = request.getParameter("rows");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        Map<String, Object> listParam = new HashMap<String, Object>();
        try {
            String sql = " AND PARENT_ID = '" + parentId + "'";
            if (null != tableId && !"".equals(tableId)) {
                list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, tableId, pageNo, pageSize, sql, listParam);
            }
            // this.getAttachNum(list);

            // 判断是否存在库房组件接口
            if (null != storeroommanagerIntfsService) {
                // 数据ids
                String positionIds = "";
                for (int i = 0; i < list.size(); i++) {
                    Map<String, Object> m = list.get(i);
                    positionIds += (String) m.get("ID");
                    if (i != list.size() - 1) {
                        positionIds += ",";
                    }
                }
                Map<String, Object> positionMap = new HashMap<String, Object>();
                positionMap.put("IDS", positionIds);
                // 通过数据id获取存放位置map
                Map<String, Object> storeMap = this.storeroommanagerIntfsService.getStoreRoomPositionMessageByRecordIdsByIntfs(positionMap);
                // 通过数据id获取存放位置,并添加到存放位置字段中
                for (int i = 0; i < list.size(); i++) {
                    Map<String, Object> m = list.get(i);
                    String id = m.get("ID") + "";
                    String position = storeMap.get(id) + "";
                    if ("null".equals(position)) {
                        position = "";
                    }
                    m.put("ARCHIVE_POSITION", position);
                }
            }

            String total = "0";
            if (null != list && list.size() > 0) {
                total = list.get(0).get("ROW_COUNT") + "";
            }
            if (null == list) {
                list = new ArrayList<Map<String, Object>>();
            }
            mav.addObject("flag", OpResult.success.ordinal());
            mav.addObject("total", total);
            mav.addObject("rows", list);
        } catch (Exception e) {
            mav.addObject("total", 0);
            mav.addObject("rows", list);
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 读取归档数据方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getSubmitData")
    public ModelAndView getSubmitData(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String id = request.getParameter("id");
        String sysId = request.getParameter("sysId");
        try {
            LantopSubmit ls = this.deptdocarrangeService.getSubmitById(id);
            String entryData = this.deptdocarrangeService.getTaskNumberById(id);
            String[] entryDatas = entryData.split("_");
            if (null != ls) {
                if (null != ls.getSubmitUserId() && !"".equals(ls.getSubmitUserId())) {
                    ls.setSubmitUserName(userLoader.getSysUserById(ls.getSubmitUserId()).getName());
                }
                if (null != ls.getSubmitDeptId() && !"".equals(ls.getSubmitDeptId())) {
                    ls.setSubmitDeptName(deptLoader.getSysDeptTl(ls.getSubmitDeptId(), "zh_CN").getDeptName());
                }
                if (null != ls.getRcvUserId() && !"".equals(ls.getRcvUserId())) {
                    ls.setRcvUserName(userLoader.getSysUserById(ls.getRcvUserId()).getName());
                }
                if (null != ls.getRcvDeptId() && !"".equals(ls.getRcvDeptId())) {
                    ls.setRcvDeptName(deptLoader.getSysDeptTl(ls.getRcvDeptId(), "zh_CN").getDeptName());
                }
            }
            // 根据归档ID查找数据归档单位名称
            String deptName = deptdocarrangeService.getDeptNameBySubmitId(id);
            mav.addObject("deptName", deptName);
            mav.addObject("taskNumber", entryDatas[0]);
            mav.addObject("taskStatus", entryDatas[1]);
            mav.addObject("id", id);
            mav.addObject("sysId", sysId);
            mav.addObject("ls", ls);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 获得归档明细方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getSubmitItemByIds")
    public ModelAndView getSubmitItemByIds(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String id = request.getParameter("id");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String pageNo = request.getParameter("page");
        String pageSize = request.getParameter("rows");
        try {
            LantopSubmit ls = this.deptdocarrangeService.getSubmitById(id);
            String tableId = ls.getArchiveTableId();
            //SanXia update by An start 案卷级
            boolean isAn = false;
            List<LantopSubmitItem> lsiList = this.deptdocarrangeService.getSubmitItemBySid(ls.getId(), tableId);

            //Sanxia update by qxy start 修改原因:直接的取集合的第一个下标容易造成空指针！  影响到专职档案人员撤销功能。
            String tableName = "";
            if (lsiList.size() != 0){
                tableName = lsiList.get(0).getArchiveTableName();
            }

            tableName = tableName.substring(tableName.length() - 3, tableName.length());

            if ("AJJ".equals(tableName)) {
                tableId = lsiList.get(0).getArchiveTableId();
                List<Map<String, Object>> table = this.deptdocarrangeService.getTableIdByAnTableId(tableId);
                tableId = table.get(0).get("TABLE_ID") != null ? table.get(0).get("TABLE_ID").toString() : tableId;
                isAn = true;
            }
            // 归档超过千条数据，详细数据报错修改
            String sql = "";
            if (!isAn) {
                sql = " AND ID IN (";
                sql += " SELECT ARCHIVE_RCD_ID FROM LANTOP_SUBMIT_ITEM WHERE LANTOP_SUBMIT_ID = '" + ls.getId() + "' AND ARCHIVE_TABLE_ID = '" + tableId + "' ";
                sql += ")";
            } else {
                sql = " AND PARENT_ID IN (";
                sql += "SELECT ARCHIVE_RCD_ID FROM LANTOP_SUBMIT_ITEM WHERE LANTOP_SUBMIT_ID='" + ls.getId() + "' AND ARCHIVE_TABLE_ID = '" + lsiList.get(0).getArchiveTableId() + "' ";
                sql += ")";
            }
            //SanXia update by An end
            /*
             * List<LantopSubmitItem> lsiList = this.deptdocarrangeService.getSubmitItemBySid(ls.getId(), tableId); if (lsiList.size() > 0) { tableId =
             * lsiList.get(0).getArchiveTableId(); } String sql = " AND ID IN ("; for (int i = 0; i < lsiList.size(); i++) { sql += "'" + lsiList.get(i).getArchiveRcdId() + "',"; }
             * if (lsiList.size() < 1) { sql += "'',"; } sql = sql.substring(0, sql.length() - 1); sql += ")";
             */
            Map<String, Object> listParam = new HashMap<String, Object>();
            List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, tableId, pageNo, pageSize, sql, listParam);
            // this.getAttachNum(list);

            // 判断是否存在库房组件接口
            if (null != storeroommanagerIntfsService) {
                // 数据ids
                String positionIds = "";
                for (int i = 0; i < list.size(); i++) {
                    Map<String, Object> m = list.get(i);
                    positionIds += (String) m.get("ID");
                    if (i != list.size() - 1) {
                        positionIds += ",";
                    }
                }
                Map<String, Object> positionMap = new HashMap<String, Object>();
                positionMap.put("IDS", positionIds);
                // 通过数据id获取存放位置map
                Map<String, Object> storeMap = this.storeroommanagerIntfsService.getStoreRoomPositionMessageByRecordIdsByIntfs(positionMap);
                // 通过数据id获取存放位置,并添加到存放位置字段中
                for (int i = 0; i < list.size(); i++) {
                    Map<String, Object> m = list.get(i);
                    String rid = m.get("ID") + "";
                    String position = storeMap.get(rid) + "";
                    if ("null".equals(position)) {
                        position = "";
                    }
                    m.put("ARCHIVE_POSITION", position);
                }
            }

            String total = "0";
            if (null != list && list.size() > 0) {
                total = list.get(0).get("ROW_COUNT") + "";
            }
            if(list.size()>0 && list.get(0).containsKey("ARCHIVE_IN_NUM")){
                Collections.sort(list, new Comparator<Map<String, Object>>() {
                    @Override
                    public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                        return (Integer.parseInt(o1.get("ARCHIVE_IN_NUM").toString()))-(Integer.parseInt(o2.get("ARCHIVE_IN_NUM").toString()));
                    }
                });
            }
            mav.addObject("total", total);
            mav.addObject("rows", list);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 案卷目录跳转add页面
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/toAddAnJsp")
    public ModelAndView toAddAnJsp(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String id = request.getParameter("id");
        String dialogId = request.getParameter("dialogId");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String isKYDA = request.getParameter("isKYDAAJ");
        String parentType = request.getParameter("parentType");//2档案类型
        request.setAttribute("parentType", parentType);
        String userId = SessionHelper.getLoginSysUserId(request);
        String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
        SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
        String orgCode = so.getOrgCode();
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("currentUserId", userId);
        param.put("currentDeptId", deptId);
        param.put("currentOrgCode", orgCode);
        param.put("nodeId", nodeId);
        Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
        param.put("languageCode", sessionLanguageCode);

        String loginUserSecretLevel = SessionHelper.getLoginSysUser(request).getSecretLevel();
        Map<String, Object> pa = new HashMap<String, Object>();
        pa.put("languageCode", sessionLanguageCode);
        pa.put("userSecretLevel", loginUserSecretLevel);
        try {
            /***** 2015/07/25增加-郭亮-拼接条件sql *****/
            String sql = " AND NODE_ID = '" + nodeId + "' AND ARCHIVE_STATUS = '1'";// 模块固定条件sql
            Map<String, String> userAuthMap = userAuthIntfsService.getUserAuthDatasByIntfs(SessionHelper.getCurrentOrgId(request), SessionHelper.getCurrentDeptId(request), sysId, "3", userId, "LANTOP_AUTH_SERVER_USERSET", nodeId, tableId, "", null);// 权限Map
            String userAuthsql = userAuthMap.get("SQL");// 权限sql
            sql = sql + userAuthsql;// 最终条件sql
            param.put("userAuthsql", sql);
            /***** 2015/07/25增加-郭亮-拼接条件sql *****/

            //List<Map<String, Object>> addAnFieldList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, tableId, "1", id, param);
            List<Map<String, Object>> addAnFieldList = null;
            if ("2".equals(parentType)) {
                //SanXiaFiles update by huangjian start
                param.put("archiveFlag", "1");//3馆藏，2著录整理  1整理归档
                addAnFieldList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfsItera(orgId, deptId, sysId, tableId, "1", id, param);
            } else {
                addAnFieldList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, tableId, "1", id, param);
            }

            String deptCols = this.billDefineManagerIntfsService.getSelectDialogStringByIntfs1(orgId, deptId, sysId, tableId); // 查找选部门，选人的字段字符串
            Map<String, Map<String, String>> mapCode = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, tableId, "", "1", pa);// 获取字段通用代码数据//


            net.sf.json.JSONArray ja = net.sf.json.JSONArray.fromObject(addAnFieldList);
            String jaString = ja.toString();
            mav.addObject("dataJson", jaString);
            /***** 2016/04/13增加 wangzp 页面动态显示 *****/
            // List<Map<String, Object>> modelList = this.archiveClassManagerIntfsService.getModelData(nodeId);
            // String modelId = "";
            // if (modelList.size() > 0) {
            // modelId = (String) modelList.get(0).get("ID");
            // }
            Map<String, Object> colMap = new HashMap<String, Object>();
            colMap.put("tableId", tableId);
            colMap.put("nodeId", nodeId);
            colMap.put("sysId", sysId);
            colMap.put("flag", "1");
            colMap.put("orgId", orgId);
            colMap.put("deptId", deptId);
            //Map<String, Object> dynamicMap = this.commTableManagerIntfsService.getColumnPageMap(colMap);

            //SanXiaFiles update by huangjian  start 2019 05 31
            Map<String, Object> dynamicMap = null;
            if ("2".equals(parentType)) {
                colMap.put("archiveStatus", "1");//预归档l
                dynamicMap = this.commTableManagerIntfsService.getColumnPageMapItera(colMap, addAnFieldList);
            } else {
                dynamicMap = this.commTableManagerIntfsService.getColumnPageMap(colMap);
            }

            //SanXiaFiles update by huangjian  end 2019 05 31


            dynamicMap.put("MODEL_CODE", "deptdocarrangeAddAn");
            dynamicMap.put("FORM_CODE", "addAnForm");
            String addHtml = this.billDefineDynamicService.getDynamicAddHtml(addAnFieldList, mapCode, dynamicMap);
            mav.addObject("addHtml", addHtml);

            mav.addObject("mapCode", mapCode);
            mav.addObject("deptCols", deptCols);
            mav.addObject("addAnFieldList", addAnFieldList);
            mav.addObject("nodeId", nodeId);
            mav.addObject("sysId", sysId);
            mav.addObject("tableId", tableId);
            mav.addObject("dialogId", dialogId);
            mav.addObject("isKYDA", isKYDA);
            mav.addObject("sysFlag", sysFlag);
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeAddAn");
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }
    /**
     * 离线数据下载 跳转字段对应设置页面
     * param: id 离线数据包id
     *
     * @param request
     * @return
     */
    @RequestMapping("/toFieldMapSetItem")
    @ResponseBody
    public ModelAndView toFieldMapSetItem(String id, String dialogId, String nodeId, HttpServletRequest request) throws Exception {
        ModelAndView mv = new ModelAndView();
        SysUser loginSysUser = SessionHelper.getLoginSysUser(request);
        Map<String, Object> param = new HashMap<>();
        param.put("id", id);
        param.put("deptId", loginSysUser.getDeptId());
        param.put("orgId", SessionHelper.getCurrentOrgId(request));
        param.put("nodeId", nodeId);
        Map<String, Object> resultMap = deptdocarrangeService.toFieldMapSetItem(param);
        if (resultMap != null && resultMap.size() > 0) {
            Object nodeType = resultMap.get("nodeType");
            mv.addObject("nodeType", nodeType);
            mv.addObject("TableName", resultMap.get("TableName"));
            mv.addObject("TagColList", JSON.toJSONString(resultMap.get("TagColList")));
            mv.addObject("OffCollist", JSON.toJSONString(resultMap.get("OffCollist")));
            mv.addObject("OffCollistAN", "[]");
            mv.addObject("TagColListAN", "[]");
            if ("2".equals(resultMap.get("nodeType"))) {
                mv.addObject("anTableName", resultMap.get("anTableName"));
                mv.addObject("wjTableName", resultMap.get("wjTableName"));
                mv.addObject("OffCollistAN", JSON.toJSONString(resultMap.get("OffCollistAN")));
                mv.addObject("TagColListAN", JSON.toJSONString(resultMap.get("TagColListAN")));
            }
        }
        mv.addObject("dialogId", dialogId);
        mv.addObject("id", id);
        mv.setViewName("avicit/im/lantop/fileaccept/offlineFieldMapSetItem");
        return mv;
    }
    /** SanXiaFiles create by zhaoxiaolong 存放查询维度公共数据集合 **/
    private Map<String,Object> queryDimensionMap = new HashMap<>();

    /**
     * 获得案卷目录列表数据集合
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getAllAnTableList")
    public ModelAndView getAllAnTableList(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        // 查询类型（查询入口）
        String searchFlag = request.getParameter("searchFlag");
        // 查询区域结果中查询flag
        String resultSearchFlag = request.getParameter("resultSearchFlag");
        // 高级查询结果中查询flag
        String highSelectResultSearchFlag = request.getParameter("highSelectResultSearchFlag");
        String orderCols = request.getParameter("orderCols");
        String startStatus = request.getParameter("startStatus");
        String isParent = request.getParameter("isParent");
        String json = request.getParameter("param");
        String status = "0"; //request.getParameter("status");
        // String share = request.getParameter("share");
        String tableId = request.getParameter("tableId");
        String nodeId = request.getParameter("nodeId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String userId = SessionHelper.getLoginSysUserId(request);
        String sysId = request.getParameter("sysId");
        String page = request.getParameter("page");
        String rows = request.getParameter("rows");
        String pageNo = request.getParameter("pageNo");
        String pageSize = request.getParameter("pSize");// 取得一页显示的数量
        String flowStatus = request.getParameter("flowStatus"); // 流程状态
        if (null == pageNo) {
            if (page!=null&&!"".equals(page)){
                pageNo=page;
            }else {
                pageNo = "1";
            }
        }
        if (null == pageSize) {
            if (rows!=null&&!"".equals(rows)){
                pageSize=rows;
            }else {
                pageSize = "100";
            }
        }

        String queryDimension = request.getParameter("queryDimension"); //拼接SQL查询条件维度过滤 SanXiaFiles create by zhaoxiaolong
        if(queryDimensionMap==null||queryDimensionMap.size()==0){
            queryDimensionMap.put("queryDimension",queryDimension);
        }else {
            String queryDimensionTest = (String) queryDimensionMap.get("queryDimension");
            if (queryDimension!=null&&!"".equals(queryDimension)&&queryDimension!=queryDimensionTest){
                queryDimensionMap.put("queryDimension",queryDimension);
            }else {
                queryDimension = (String) queryDimensionMap.get("queryDimension");
            }
        }

        // SanXiaFiles create by zhaoxiaolong 查询当前表是否存在归档单位（ARCHIVE_DEPT）和项目负责人（XMFZR）字段
        boolean isExistArchiveDept = false; // 是否存在归档部门字段
        boolean isExistxmfzr = false; // 是否存在项目负责人字段
        boolean isExistNodeName = false; // 当前数据节点的父类是否是技术类
        boolean fileTabFlag = false; // 是否为文件级
        String loginName = SessionHelper.getLoginName(request);
        loginName = loginName.toUpperCase(); // 转化为大写
        SysUser sysUser = SessionHelper.getLoginSysUser(request);
        String userName = sysUser.getName();
        StringBuffer searchSbSql = new StringBuffer(); // 根据维度进行拼接SQL
        if(tableId!=null&&!tableId.equals("")){
            String archiveDeptName = "ARCHIVE_DEPT"; // 归档部门字段名称
            String xmfzrName = "XMFZR"; // 项目负责人字段名称
            isExistArchiveDept = isExistColumn(archiveDeptName,tableId);
            isExistxmfzr = isExistColumn(xmfzrName,tableId);
        }
        if (nodeId!=null&&nodeId!=""){
            isExistNodeName = getParentNodeDataByNodeNameAndNodeId(nodeId,"技术类"); // 查询当前数据节点的父级是否有技术类
        }
        // SanXiaFiles create by zhaoxiaolong 是否为文件级表名
        if (tableId!=null&&!"".equals(tableId)&&!"null".equals(tableId)){
            StringBuffer sbTabSql = new StringBuffer();
            sbTabSql.append("SELECT TABLE_NAME FROM CBB_TABLES WHERE ID='"+tableId+"'");
            List<Map<String,Object>> tabDataList = this.jdbcAvicit.getJdbcTemplate().queryForList(sbTabSql.toString());
            if(tabDataList!=null&&tabDataList.size()>0){
                String tabName = tabDataList.get(0).get("TABLE_NAME").toString();
                if (tabName.indexOf("WJJ")!=-1||tabName.indexOf("WJ")!=-1){
                    fileTabFlag = true;
                }
            }
        }
        if (queryDimension!=null&&queryDimension!=""){
            if(isExistArchiveDept||isExistxmfzr){
                if(queryDimension.equals("1")){  // 兼职档案管理员根据归档部门是当前部门的，并且如果该数据节点是技术类下的，需要加上项目负责人是当前登录用户的过滤
                    String currentDeptName = SessionHelper.getCurrentDeptName(request); // 当前登录部门名称
                    if (isExistArchiveDept){
                        searchSbSql.append(" AND ( ARCHIVE_DEPT = '"+currentDeptName+"' OR   CREATED_BY='"+userId+"' OR DEPT_ID='"+deptId+"' ) ");
                    }else {
                        mav.addObject("total", 0);
                        mav.addObject("rows", new ArrayList<>());
                        return mav;
                    }
                    if (isExistNodeName){ // 父级是技术类需要增加项目负责人查询SQL
                        if(!fileTabFlag){ // 案卷需要判断项目负责人是否存在
                            if (isExistxmfzr){
                                if(searchSbSql!=null&&searchSbSql.toString()!=""){
                                    searchSbSql = new StringBuffer();
                                    searchSbSql.append(" AND ( CREATED_BY='"+userId+"' OR ARCHIVE_DEPT = '"+currentDeptName+"' OR DEPT_ID='"+deptId+"' ");
                                    searchSbSql.append(" OR ( UPPER(XMFZR) = '"+userName+"("+loginName+")'  ) ) ");
                                }else {
                                    searchSbSql.append(" AND ( ( UPPER(XMFZR) = '"+userName+"("+loginName+")' )  OR   CREATED_BY='"+userId+"' ) ");
                                }
                            }else {
                                // 如果没有项目负责人字段，查询创建人是自己的
                                searchSbSql.append(" AND  CREATED_BY='"+userId+"'  ");
                            }
                        }
                    }
                }else if (queryDimension.equals("2")){
                    if (fileTabFlag){ // 文件级，不需要校验项目负责人
                        searchSbSql.append(" AND  CREATED_BY='"+userId+"'  ");
                    }else {
                        if (isExistNodeName){ // 父级是技术类需要增加项目负责人查询SQL
                            if (isExistxmfzr){
                                searchSbSql.append(" AND ( ( UPPER(XMFZR) = '"+userName+"("+loginName+")' )  OR   CREATED_BY='"+userId+"'  ) ");
                            }else {
                                // 如果没有项目负责人字段，查询创建人是自己的
                                searchSbSql.append(" AND  CREATED_BY='"+userId+"'  ");
                            }
                        }else {
                            // 文件级，不需要校验项目负责人
                            searchSbSql.append(" AND  CREATED_BY='"+userId+"'  ");
                        }
                    }
                }
            }else {
                mav.addObject("total", 0);
                mav.addObject("rows", new ArrayList<>());
                return mav;
            }
        }

        String onlyDeptSee = "0"; // 仅部门可见 0 否 1 是
        List<Map<String, Object>> listNode = archiveclassmanagerService.getArchiveClassTreeNodeByNodeId(nodeId);
        if (listNode.size() > 0) {
            Map<String, Object> map = listNode.get(0);
            Object attribute01 = map.get("ATTRIBUTE_01");
            if (null != attribute01 && !attribute01.equals("")) {
                onlyDeptSee = attribute01.toString();
            }
        }
        // 高级查询sql语句
        String whereSql = request.getParameter("whereSql");
        // 高级查询带表名语句
        String highSelectSql = request.getParameter("highSelectSql");
        // 打印查询sql语句
        StringBuffer printQuerySql = new StringBuffer();
        // 需要查询的表名
        String printTableName = "";
        List<Map<String, Object>> tableColumnList = this.commTableManagerIntfsService.getCbbTableAndColumnsByTabIdByIntfs(tableId);
        if (tableColumnList.size() > 0) {
            printTableName = (String) tableColumnList.get(0).get("TABLE_NAME");
        }
        StringBuffer sb = new StringBuffer();
        if (null == isParent || "".equals(isParent)) {
            sb.append(" AND NODE_ID = '" + nodeId + "' ");
            sb.append(searchSbSql.toString());
        } else {
            sb.append(" AND NODE_ID IN (");
            List<Map<String, Object>> nodeList = this.deptdocarrangeService.getChildNodeIdByParentId(isParent);
            String ids = "";
            for (int i = 0; i < nodeList.size(); i++) {
                Map<String, Object> map = nodeList.get(i);
                ids += "'" + map.get("ID") + "'";
                if (i != nodeList.size() - 1) {
                    ids += ",";
                }
            }
            sb.append(ids + ")");
        }
        // 定义查询区域查询条件
        StringBuffer searchSb = new StringBuffer();
        // 定义查询区域带表名查询条件
        StringBuffer searchTableSb = new StringBuffer();
        // 日志查询条件
        String searchString = "";
        // 文件动态查询字段集合
        Map<String, Object> searchParam = new HashMap<String, Object>();
        searchParam.put("showFlagJG", "2");
        searchParam.put("showFlagYM", "1");
        List<Map<String, Object>> fileSearchList = this.commTableManagerIntfsService.getCbbTabColumnsByMap(orgId, deptId, sysId, tableId, searchParam);
        if (fileSearchList.size() > 0 && null != json && !"".equals(json) && !"{}".equals(json)) {
            json = URLDecoder.decode(URLDecoder.decode(json, "utf-8"), "utf-8");
            sb.append(" AND (");
            printQuerySql.append(" AND (");
            for (int i = 0; i < fileSearchList.size(); i++) {
                Map<String, Object> fileSearchMap = fileSearchList.get(i);
                String colLabel = (String) fileSearchMap.get("COL_LABEL");
                String colName = (String) fileSearchMap.get("COL_NAME");
                String colType = (String) fileSearchMap.get("COL_TYPE");
                if ("date".equals(colType)) {
                    searchString += colLabel + " 等于 " + json;
                    sb.append(colName + " = TO_DATE('" + json + "', 'yyyy-MM-dd')");
                    printQuerySql.append(colName + " = TO_DATE('" + json + "', 'yyyy-MM-dd')");
                } else if ("integer".equals(colType) || "float".equals(colType)) {
                    searchString += colLabel + " 等于 " + json;
                    sb.append(colName + " = '" + json + "'");
                    printQuerySql.append(colName + " = '" + json + "'");
                } else {
                    searchString += colLabel + " 包含 " + json;
                    sb.append(colName + " LIKE '%" + json + "%'");
                    printQuerySql.append(colName + " LIKE '%" + json + "%'");
                }
                if (i != fileSearchList.size() - 1) {
                    searchString += " 或者 ";
                    sb.append(" OR ");
                    printQuerySql.append(" OR ");
                }
            }
            sb.append(" ) ");
            printQuerySql.append(" ) ");
        }
        //SanXiaFiles update by huangjian 2019-10-09 ARCHIVE_STATUS 不能为空
        if (null != status && !"".equals(status)) {
            if ("2".equals(status)) {
                sb.append(" AND ARCHIVE_STATUS = '3'");
                printQuerySql.append(" AND " + printTableName + ".ARCHIVE_STATUS = '3'");
            } else if ("1".equals(status)) {
                //sb.append(" AND (ARCHIVE_STATUS = '1' OR ARCHIVE_STATUS IS NULL OR ARCHIVE_STATUS = '')");
                //printQuerySql.append(" AND (" + printTableName + ".ARCHIVE_STATUS = '1' OR " + printTableName + ".ARCHIVE_STATUS IS NULL OR " + printTableName + ".ARCHIVE_STATUS = '')");
                sb.append(" AND (ARCHIVE_STATUS = '1' )");
                printQuerySql.append(" AND (" + printTableName + ".ARCHIVE_STATUS = '1' )");
            } else if ("0".equals(status)) {
                //sb.append(" AND (ARCHIVE_STATUS = '0' OR ARCHIVE_STATUS IS NULL OR ARCHIVE_STATUS = '')");
                //printQuerySql.append(" AND (" + printTableName + ".ARCHIVE_STATUS = '0' OR " + printTableName + ".ARCHIVE_STATUS IS NULL OR " + printTableName + ".ARCHIVE_STATUS = '')");
                sb.append(" AND (ARCHIVE_STATUS = '0' )");
                printQuerySql.append(" AND (" + printTableName + ".ARCHIVE_STATUS = '0' )");
            } else {
                //sb.append(" AND (ARCHIVE_STATUS = '1' OR ARCHIVE_STATUS = '3' OR ARCHIVE_STATUS = '4' OR ARCHIVE_STATUS IS NULL OR ARCHIVE_STATUS = '')");
                //printQuerySql.append(" AND (" + printTableName + ".ARCHIVE_STATUS = '1' OR " + printTableName + ".ARCHIVE_STATUS = '3' OR " + printTableName + ".ARCHIVE_STATUS = '4' OR " + printTableName + ".ARCHIVE_STATUS IS NULL OR " + printTableName + ".ARCHIVE_STATUS = '')");
                sb.append(" AND (ARCHIVE_STATUS = '1' OR ARCHIVE_STATUS = '3' OR ARCHIVE_STATUS = '4' OR ARCHIVE_STATUS IS NULL OR ARCHIVE_STATUS = '')");
                printQuerySql.append(" AND (" + printTableName + ".ARCHIVE_STATUS = '1' OR " + printTableName + ".ARCHIVE_STATUS = '3' OR " + printTableName + ".ARCHIVE_STATUS = '4' )");
            }
        } else {
            if (null != startStatus && !"".equals(startStatus) && "join".equals(startStatus)) {
                //sb.append(" AND (ARCHIVE_STATUS = '1' OR ARCHIVE_STATUS = '3' OR ARCHIVE_STATUS = '4' OR ARCHIVE_STATUS IS NULL OR ARCHIVE_STATUS = '') AND (ARCHIVE_FLOW_STATUS = '1' OR ARCHIVE_FLOW_STATUS IS NULL OR ARCHIVE_FLOW_STATUS = '')");
                //printQuerySql.append(" AND (" + printTableName + ".ARCHIVE_STATUS = '1' OR " + printTableName + ".ARCHIVE_STATUS = '3' OR " + printTableName + ".ARCHIVE_STATUS = '4' OR " + printTableName + ".ARCHIVE_STATUS IS NULL OR " + printTableName
                //        + ".ARCHIVE_STATUS = '') AND (" + printTableName + ".ARCHIVE_FLOW_STATUS = '1' OR " + printTableName + ".ARCHIVE_FLOW_STATUS IS NULL OR " + printTableName + ".ARCHIVE_FLOW_STATUS = '')");
                sb.append(" AND (ARCHIVE_STATUS = '1' OR ARCHIVE_STATUS = '3' OR ARCHIVE_STATUS = '4' ) AND (ARCHIVE_FLOW_STATUS = '1' OR ARCHIVE_FLOW_STATUS IS NULL OR ARCHIVE_FLOW_STATUS = '')");
                printQuerySql.append(" AND (" + printTableName + ".ARCHIVE_STATUS = '1' OR " + printTableName + ".ARCHIVE_STATUS = '3' OR " + printTableName + ".ARCHIVE_STATUS = '4' ) AND (" + printTableName + ".ARCHIVE_FLOW_STATUS = '1' )");
            } else {
                //sb.append(" AND (ARCHIVE_STATUS = '1' OR ARCHIVE_STATUS = '3' OR ARCHIVE_STATUS = '4' OR ARCHIVE_STATUS IS NULL OR ARCHIVE_STATUS = '')");
                //printQuerySql.append(" AND (" + printTableName + ".ARCHIVE_STATUS = '1' OR " + printTableName + ".ARCHIVE_STATUS = '3' OR " + printTableName + ".ARCHIVE_STATUS = '4' OR " + printTableName + ".ARCHIVE_STATUS IS NULL OR " + printTableName + ".ARCHIVE_STATUS = '')");
                sb.append(" AND (ARCHIVE_STATUS = '1' OR ARCHIVE_STATUS = '3' OR ARCHIVE_STATUS = '4' )");
                printQuerySql.append(" AND (" + printTableName + ".ARCHIVE_STATUS = '1' OR " + printTableName + ".ARCHIVE_STATUS = '3' OR " + printTableName + ".ARCHIVE_STATUS = '4' )");
            }
        }
        // 流程状态字段过滤
        if (null != flowStatus && !"".equals(flowStatus)) {
            if (!"0".equals(flowStatus)) {
                if ("1".equals(flowStatus)) {
                    sb.append(" AND (ARCHIVE_FLOW_STATUS = '" + flowStatus + "' OR ARCHIVE_FLOW_STATUS = '' OR ARCHIVE_FLOW_STATUS IS NULL OR ARCHIVE_FLOW_STATUS = '2')");
                    printQuerySql.append(" AND (" + printTableName + ".ARCHIVE_FLOW_STATUS = '" + flowStatus + "' OR " + printTableName + ".ARCHIVE_FLOW_STATUS = '2' OR " + printTableName + ".ARCHIVE_FLOW_STATUS = '' OR " + printTableName + ".ARCHIVE_FLOW_STATUS IS NULL)");
                } else {
                    sb.append(" AND ARCHIVE_FLOW_STATUS = '" + flowStatus + "'");
                    printQuerySql.append(" AND " + printTableName + ".ARCHIVE_FLOW_STATUS = '" + flowStatus + "'");
                }
            }
        } else {
            sb.append(" AND (ARCHIVE_FLOW_STATUS = '1' OR ARCHIVE_FLOW_STATUS = '2' OR ARCHIVE_FLOW_STATUS = '' OR ARCHIVE_FLOW_STATUS IS NULL)");
            printQuerySql.append(" AND (" + printTableName + ".ARCHIVE_FLOW_STATUS = '1' OR " + printTableName + ".ARCHIVE_FLOW_STATUS = '2' OR " + printTableName + ".ARCHIVE_FLOW_STATUS = '' OR " + printTableName + ".ARCHIVE_FLOW_STATUS IS NULL)");
        }
        if (onlyDeptSee.equals("1")) {
            sb.append(" AND DEPT_ID = '" + deptId + "'");
            printQuerySql.append(" AND " + printTableName + ".DEPT_ID = '" + deptId + "'");
        }
        String highSelectSqlString = "";
        // 高级查询语句
        if (null != whereSql && !"".equals(whereSql)) {
            highSelectSqlString = whereSql.replace("where", " and ");
        }
        String printHighSelectSqlString = "";
        // 高级查询语句
        if (null != highSelectSql && !"".equals(highSelectSql)) {
            printHighSelectSqlString = highSelectSql.replace("where", " and ");
        }
        Map<String, Object> listParam = new HashMap<String, Object>();
        Map<String, String> orderMap = new LinkedHashMap<String, String>();
        JSONArray orderColsJSONArray = JSON.parseArray(orderCols);
        Map<String, String> orderColsMapString = new HashMap<String, String>();
        int o = 0;
        if (null != orderCols && !orderCols.equals("") && !orderCols.equals("null")) {
            for (int i = 0; i < orderColsJSONArray.size(); i++) {
                String orderColsJSONString = orderColsJSONArray.get(i).toString();
                orderColsMapString = JsonUtils.newInstance().Json2Bean2Form(orderColsJSONString, Map.class);
                String name = orderColsMapString.get("COL_NAME");
                String sort = orderColsMapString.get("SORT_CODE");
                if (null != sort && !sort.equals("") && !sort.equals("null")) {
                    if (sort.equals("A")) {
                        sort = "ASC";
                        o++;
                    } else if (sort.equals("D")) {
                        sort = "DESC";
                        o++;
                    }
                }
                orderMap.put(name, sort);
            }
        }
        if(o == 0){
            //未进自定义排序，那么给默认排序字段
            orderMap.put("CREATION_DATE", "DESC");
        }
        //做一个自定义排序标识
        listParam.put("customSorting", true);
        //listParam.put("customSorting", "1");
        listParam.put("searchOrder", orderMap);
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("userSecretLevel", SessionHelper.getLoginSysUser(request).getSecretLevel());
        Map<String, String> map = this.userAuthIntfsService.getUserAuthDatasByIntfs(orgId, deptId, sysId, "3", SessionHelper.getLoginSysUserId(request), "LANTOP_AUTH_SERVER_USERSET", nodeId, tableId, "", param);
        String authSql = map.get("SQL");
        sb.append(authSql);
        param.put("isEnable", "Y");
        Map<String, String> authmap = this.userAuthIntfsService.getUserAuthDatasByIntfs(orgId, deptId, sysId, "3", SessionHelper.getLoginSysUserId(request), "LANTOP_AUTH_SERVER_USERSET", nodeId, tableId, "", param);
        String authMapSql = authmap.get("SQL");
        printQuerySql.append(authMapSql);

        // 定位刷新id,需要定位时，才会有值，不定位时，该值为空
        String selectRecordId = request.getParameter("selectRecordId");
        Map<String, Object> dwParam = new HashMap<String, Object>();
        dwParam.put("TABLE_ID", tableId);
        dwParam.put("PAGE_SIZE", pageSize);
        dwParam.put("SELECT_RECORD_ID", selectRecordId);

        dwParam.put("ORG_ID", orgId);
        dwParam.put("DEPT_ID", deptId);
        dwParam.put("SYS_ID", sysId);

        String searchCondition = "";
        // 根据结果中查询复选框，追加查询条件
        if ("high".equals(searchFlag)) {
            if ("on".equals(highSelectResultSearchFlag)) {
                searchCondition = sb.toString() + searchSb.toString() + highSelectSqlString;
            } else {
                searchCondition = sb.toString() + highSelectSqlString;
            }
        } else {
            if ("on".equals(resultSearchFlag)) {
                searchCondition = sb.toString() + searchSb.toString() + highSelectSqlString;
            } else {
                searchCondition = sb.toString() + searchSb.toString();
            }
        }
        if (null != selectRecordId && !"".equals(selectRecordId) && !"-1".equals(selectRecordId)) {
            List<String> dwList = this.billDefineManagerIntfsService.getDatasPageNumAndIndexByTableIdRecordId(dwParam, searchCondition);
            String changeNo = dwList.get(0);
            String dataIndex = dwList.get(1);
            mav.addObject("dataIndex", Double.valueOf(dataIndex).intValue());
        }
        mav.addObject("pageNo", pageNo);
        List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, tableId, pageNo, pageSize, searchCondition, listParam);
        //SanXiaFiles add by huangjian 2019-12-26 回显四性检测状态  -- 整理归档 案卷级

        Map<String, Object> statusParam = new HashMap<String, Object>();
        statusParam.put("tableId", tableId);
        statusParam.put("orgId", orgId);
        statusParam.put("deptId", deptId);
        statusParam.put("sysId", sysId);
        statusParam.put("nodeId", nodeId);
        statusParam.put("stage", "1");//1档案整理，2整理归档，3档案保管
        statusParam.put("dataType", "1");//0文件级 1案卷级 2卷内件
        fourCheckService.getFourCheckStatus(list,statusParam);
        // 判断是否存在库房组件接口
        if (null != storeroommanagerIntfsService) {
            // 数据ids
            String positionIds = "";
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> m = list.get(i);
                positionIds += (String) m.get("ID");
                if (i != list.size() - 1) {
                    positionIds += ",";
                }
            }
            Map<String, Object> positionMap = new HashMap<String, Object>();
            positionMap.put("IDS", positionIds);
            // 通过数据id获取存放位置map
            Map<String, Object> storeMap = this.storeroommanagerIntfsService.getStoreRoomPositionMessageByRecordIdsByIntfs(positionMap);
            // 通过数据id获取存放位置,并添加到存放位置字段中
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> m = list.get(i);
                String id = m.get("ID") + "";
                String position = storeMap.get(id) + "";
                if ("null".equals(position)) {
                    position = "";
                }
                m.put("ARCHIVE_POSITION", position);
            }
        }
        String total = "0";
        if (null != list && list.size() > 0) {
            total = list.get(0).get("ROW_COUNT") + "";
        }
        // 添加日志
        String modelName = "";
        SysMenu sm = menuAPI.getSysMenuByCode(menuCode, SessionHelper.getApplicationId());
        if (null != sm) {
            modelName = sm.getName();
        }
        String path = this.archiveClassManagerIntfsService.getModelFileNameByNodeId(nodeId);
        // 条目日志查询记录
        Map<String, Object> paramsLog = new HashMap<String, Object>();
        paramsLog.put("searchType", "1");
        paramsLog.put("modelName", modelName);
        paramsLog.put("tableName", path);
        paramsLog.put("searchCondition", searchString);
        paramsLog.put("searchResultTotal", Integer.parseInt(total));
        paramsLog.put("orgId", orgId);
        paramsLog.put("deptId", deptId);
        paramsLog.put("sysId", sysId);
        // 调用检索日志保存接口
        lantopSearchLogIntfsService.saveLantopSearchLogByMap(paramsLog);
        // 根据结果中查询复选框，追加查询条件
        if ("on".equals(resultSearchFlag)) {
            sb.append(searchSb);
            printQuerySql.append(searchTableSb);
        }
        // 根据高级查询结果中查询复选框，追加查询条件
        if ("on".equals(highSelectResultSearchFlag)) {
            sb.append(highSelectSqlString);
            printQuerySql.append(printHighSelectSqlString);
        }
        mav.addObject("publicQuerySql", sb.substring(5, sb.length()));
        mav.addObject("printQuerySql", printQuerySql.substring(5, printQuerySql.length()));
        mav.addObject("total", total);
        mav.addObject("rows", list);
        return mav;
    }

    /**
     * 通过ids获得案卷数据集合
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getAnDatasByIds")
    public ModelAndView getAnDatasByIds(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String ids = request.getParameter("ids");
        String table = request.getParameter("table");
        String tableId = request.getParameter("tableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String pageNo = request.getParameter("page");
        String pageSize = request.getParameter("rows");
        String sysId = request.getParameter("sysId");
        String[] idsan = null;
        String[] idsfile = null;
        Map<String, Object> listParam = new HashMap<String, Object>();
        List<Map<String, Object>> searchList = new ArrayList<Map<String, Object>>();
        if (table.equals("file")) {
            // 文件归档
            if (null != ids && !"".equals(ids)) {
                idsfile = ids.split(";");
                for (int i = 0; i < idsfile.length; i++) {
                    String sql = " and ID = '" + idsfile[i] + "'";
                    List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, tableId, pageNo, pageSize, sql, listParam);
                    for (int j = 0; j < list.size(); j++) {
                        searchList.add(list.get(j));
                    }
                }
            }
        } else {
            // 案卷归档
            if (null != ids && !"".equals(ids)) {
                idsan = ids.split(";");
                for (int i = 0; i < idsan.length; i++) {
                    String sql = " and ID = '" + idsan[i] + "'";
                    List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, tableId, pageNo, pageSize, sql, listParam);
                    for (int j = 0; j < list.size(); j++) {
                        searchList.add(list.get(j));
                    }
                }
            }
        }
        String total = "0";
        if (null != searchList && searchList.size() > 0) {
            total = searchList.size() + "";
        }
        mav.addObject("total", total);
        mav.addObject("rows", searchList);
        return mav;
    }

    /**
     * 跳转编辑页面方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/toEditAnJsp")
    public ModelAndView toEditAnJsp(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String id = request.getParameter("id");
        String dialogId = request.getParameter("dialogId");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String parentType = request.getParameter("parentType");//2档案类型
        String loginUserSecretLevel = SessionHelper.getLoginSysUser(request).getSecretLevel();
        Map<String, Object> pa = new HashMap<String, Object>();
        pa.put("userSecretLevel", loginUserSecretLevel);
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("nodeId", nodeId);
        try {
            Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
            param.put("languageCode", sessionLanguageCode);
            pa.put("languageCode", sessionLanguageCode);
            // 获取id对应数据
            //List<Map<String, Object>> editList = this.billDefineManagerIntfsService.getEditOrDetailFieldsAndDataByIntfs(orgId, deptId, sysId, tableId, id, "1", param);
            List<Map<String, Object>> editList = null;
            String reqMenuSource = "1";
            if ("2".equals(parentType)) {
                //SanXiaFiles update by huangjian start
                param.put("archiveFlag", reqMenuSource);//3馆藏，2著录整理  1整理归档
                editList = this.billDefineManagerIntfsService.getEditOrDetailFieldsAndDataByIntfsItera(orgId, deptId, sysId, tableId, id, "1", param);
            } else {
                editList = this.billDefineManagerIntfsService.getEditOrDetailFieldsAndDataByIntfs(orgId, deptId, sysId, tableId, id, "1", param);
            }
            String deptCols = this.billDefineManagerIntfsService.getSelectDialogStringByIntfs1(orgId, deptId, sysId, tableId); // 查找选部门，选人的字段字符串
            Map<String, Map<String, String>> mapCode = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, tableId, id, "1", pa);// 获取字段通用代码数据//
            /***** 2016/04/13增加 wangzp 页面动态显示 *****/
            net.sf.json.JSONArray ja = net.sf.json.JSONArray.fromObject(editList);
            String jaString = ja.toString();
            mav.addObject("dataJson", jaString);
            Map<String, Object> colMap = new HashMap<String, Object>();
            colMap.put("tableId", tableId);
            colMap.put("nodeId", nodeId);
            colMap.put("sysId", sysId);
            colMap.put("flag", "1");
            colMap.put("orgId", orgId);
            colMap.put("deptId", deptId);
            //Map<String, Object> dynamicMap = this.commTableManagerIntfsService.getColumnPageMap(colMap);
            //SanXiaFiels update by huangjian start
            Map<String, Object> dynamicMap = null;
            if ("2".equals(parentType)) {
                //判断来源 3馆藏，2著录整理  1整理归档
                colMap.put("archiveStatus", reqMenuSource);//3馆藏，2著录整理  1整理归档
                dynamicMap = this.commTableManagerIntfsService.getColumnPageMapItera(colMap, editList);
            } else {
                dynamicMap = this.commTableManagerIntfsService.getColumnPageMap(colMap);
            }
            //SanXiaFiels update by huangjian end
            dynamicMap.put("MODEL_CODE", "deptdocarrangeEditAn"); // 取对应的 mydocmanagerEditFile.jsp 文件名称
            dynamicMap.put("FORM_CODE", "editAnForm");
            /**根据dataId查询归档单位和责任者的id  qht*/
            List<Map<String, Object>> treeNodeIdList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "");
            String tableName = (String) treeNodeIdList.get(0).get("TABLE_NAME");
            List<Map<String, Object>> codeMap = this.billDefineManagerIntfsService.getCode(id, tableName);
            String archive_dept_id = codeMap.get(0).get("ARCHIVE_DEPT_ID") == null ? "" : codeMap.get(0).get("ARCHIVE_DEPT_ID").toString();
            if (!StringUtil.isEmpty(archive_dept_id) && !"null".equals(archive_dept_id)) {
                dynamicMap.put("ARCHIVE_DEPT_ID", codeMap.get(0).get("ARCHIVE_DEPT_ID").toString());
            } else {
                dynamicMap.put("ARCHIVE_DEPT_ID", "");
            }
            String responsible_user_id = codeMap.get(0).get("RESPONSIBLE_USER_ID") == null ? "" : codeMap.get(0).get("RESPONSIBLE_USER_ID").toString();
            if (!StringUtil.isEmpty(responsible_user_id) && !"null".equals(responsible_user_id)) {
                dynamicMap.put("RESPONSIBLE_USER_ID", responsible_user_id);
            } else {
                dynamicMap.put("RESPONSIBLE_USER_ID", "");
            }
            String editHtml = this.billDefineDynamicService.getDynamicEditHtml(editList, mapCode, dynamicMap);
            mav.addObject("editHtml", editHtml);

            mav.addObject("mapCode", mapCode);
            mav.addObject("deptCols", deptCols);
            mav.addObject("form_id", id);
            mav.addObject("mongoId", "LANTOP");
            mav.addObject("sysId", sysId);
            mav.addObject("id", id);
            mav.addObject("editList", editList);
            mav.addObject("nodeId", nodeId);
            mav.addObject("tableId", tableId);
            mav.addObject("dialogId", dialogId);
            mav.addObject("sysFlag", sysFlag);
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeEditAn");
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 跳转详细页面方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/toDetailAnJsp")
    public ModelAndView toDetailAnJsp(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String id = request.getParameter("id");
        String dialogId = request.getParameter("dialogId");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String loginUserSecretLevel = SessionHelper.getLoginSysUser(request).getSecretLevel();
        Map<String, Object> pa = new HashMap<String, Object>();
        pa.put("userSecretLevel", loginUserSecretLevel);

        Map<String, Object> param = new HashMap<String, Object>();
        param.put("nodeId", nodeId);
        try {
            Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
            param.put("languageCode", sessionLanguageCode);
            pa.put("languageCode", sessionLanguageCode);
            // 获取id对应数据
            List<Map<String, Object>> editList = this.billDefineManagerIntfsService.getEditOrDetailFieldsAndDataByIntfs(orgId, deptId, sysId, tableId, id, "3", param);
            String deptCols = this.billDefineManagerIntfsService.getSelectDialogStringByIntfs(orgId, deptId, sysId, tableId); // 查找选部门，选人的字段字符串
            Map<String, Map<String, String>> mapCode = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, tableId, id, "3", pa);// 获取字段通用代码数据//
            /***** 2016/04/13增加 wangzp 页面动态显示 *****/
            // List<Map<String, Object>> modelList = this.archiveClassManagerIntfsService.getModelData(nodeId);
            // String modelId = "";
            // if (modelList.size() > 0) {
            // modelId = (String) modelList.get(0).get("ID");
            // }
            Map<String, Object> colMap = new HashMap<String, Object>();
            colMap.put("tableId", tableId);
            colMap.put("nodeId", nodeId);
            colMap.put("sysId", sysId);
            colMap.put("flag", "3");
            colMap.put("orgId", orgId);
            colMap.put("deptId", deptId);
            Map<String, Object> dynamicMap = this.commTableManagerIntfsService.getColumnPageMap(colMap);
            dynamicMap.put("MODEL_CODE", "deptdocarrangeDetailAn");
            dynamicMap.put("FORM_CODE", "detailAnForm");
            String detailHtml = this.billDefineDynamicService.getDynamicDetailHtml(editList, mapCode, dynamicMap);
            mav.addObject("detailHtml", detailHtml);

            mav.addObject("mapCode", mapCode);
            mav.addObject("deptCols", deptCols);
            mav.addObject("form_id", id);
            mav.addObject("mongoId", "LANTOP");
            mav.addObject("sysId", sysId);
            mav.addObject("id", id);
            mav.addObject("editList", editList);
            mav.addObject("nodeId", nodeId);
            mav.addObject("tableId", tableId);
            mav.addObject("dialogId", dialogId);
            mav.addObject("sysFlag", sysFlag);
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeDetailAn");
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 跳转详细页面方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/toDetailAnJspOpen")
    public ModelAndView toDetailAnJspOpen(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String id = request.getParameter("id");
        String dialogId = request.getParameter("dialogId");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String sysFlag = request.getParameter("sysFlag");
        String loginUserSecretLevel = SessionHelper.getLoginSysUser(request).getSecretLevel();
        Map<String, Object> pa = new HashMap<String, Object>();
        pa.put("userSecretLevel", loginUserSecretLevel);

        Map<String, Object> param = new HashMap<String, Object>();
        param.put("nodeId", nodeId);
        try {
            Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
            param.put("languageCode", sessionLanguageCode);
            pa.put("languageCode", sessionLanguageCode);
            // 获取id对应数据
            List<Map<String, Object>> editList = this.billDefineManagerIntfsService.getEditOrDetailFieldsAndDataByIntfs(orgId, deptId, sysId, tableId, id, "3", param);
            String deptCols = this.billDefineManagerIntfsService.getSelectDialogStringByIntfs(orgId, deptId, sysId, tableId); // 查找选部门，选人的字段字符串
            Map<String, Map<String, String>> mapCode = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, tableId, id, "3", pa);// 获取字段通用代码数据//
            Map<String, Object> colMap = new HashMap<String, Object>();
            colMap.put("tableId", tableId);
            colMap.put("nodeId", nodeId);
            colMap.put("sysId", sysId);
            colMap.put("flag", "3");
            colMap.put("orgId", orgId);
            colMap.put("deptId", deptId);
            Map<String, Object> dynamicMap = this.commTableManagerIntfsService.getColumnPageMap(colMap);
            dynamicMap.put("MODEL_CODE", "deptdocarrangeDetailAn");
            dynamicMap.put("FORM_CODE", "detailAnForm");
            String detailHtml = this.billDefineDynamicService.getDynamicDetailHtml(editList, mapCode, dynamicMap);
            mav.addObject("detailHtml", detailHtml);

            mav.addObject("mapCode", mapCode);
            mav.addObject("deptCols", deptCols);
            mav.addObject("form_id", id);
            mav.addObject("mongoId", "LANTOP");
            mav.addObject("sysId", sysId);
            mav.addObject("id", id);
            mav.addObject("sysFlag", sysFlag);
            mav.addObject("editList", editList);
            mav.addObject("nodeId", nodeId);
            mav.addObject("tableId", tableId);
            mav.addObject("dialogId", dialogId);
            mav.addObject("flowType", "flowType");
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeDetailAn");
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 拆卷方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/updateDismantleAn")
    public ModelAndView updateDismantleAn(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String anIds = request.getParameter("ids");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String anTableId = request.getParameter("anTableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String pageNo = request.getParameter("page");
        String pageSize = request.getParameter("rows");
        pageSize = "9999";
        Map<String, Object> listParam = new HashMap<String, Object>();
        // 案卷id数组
        String[] ans = null;
        // SanXiaFiles create by zhaoxiaolong 待更新的案卷Id字符串
        StringBuffer anIds01 = new StringBuffer();
        // 需要改变的文件ids
        // String fileIds = "";
        // SanXiaFiles create by zhaoxiaolong 修改需要改变的文件ids
        StringBuffer fileIds = new StringBuffer();
        String fileIdsAry = "";
        try {
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("modleName", modleName);
            if (null != anIds && !"".equals(anIds)) {
                ans = anIds.split(";");
                for (int i = 0; i < ans.length; i++) {
                    anIds01.append(ans[i]+"','");
                    String sql = " and PARENT_ID = '" + ans[i] + "'";
                    List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, tableId, pageNo, pageSize, sql, listParam);
                    param.put("ajDataId", ans[i]);
                    for (int j = 0; j < list.size(); j++) {
                        Map<String, Object> map = list.get(j);
                        fileIds.append( map.get("ID").toString() + ";");
                        // fileIds += map.get("ID").toString() + ";";
                        /*if (j == list.size() - 1) {
                            fileIds = fileIds.substring(0, fileIds.length() - 1);
                        }*/
                        Map<String, Object> updateMap = new HashMap<String, Object>();
                        updateMap.put("ARCHIVE_IN_NUM", "");
                        // this.billDefineManagerIntfsService.updateRecordByDataIdByIntfs(orgId, deptId, sysId, nodeId, tableId, updateMap, map.get("ID").toString());
                        this.billDefineManagerIntfsService.updateRecordByDataIdWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, tableId, updateMap, map.get("ID").toString(), param);
                    }
                }
                fileIdsAry = fileIds.toString().substring(0,fileIds.toString().lastIndexOf(";"));
                Map<String, Object> mapObj = new HashMap<String, Object>();
                mapObj.put("PARENT_ID", "");
                // this.billDefineManagerIntfsService.updateRecordByDataIdsByIntfs(orgId, deptId, sysId, nodeId, tableId, mapObj, fileIds);
                param.put("ajDataId", "");
                param.put("modleName", modleName);
                this.billDefineManagerIntfsService.updateRecordByDataIdsWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, tableId, mapObj, fileIdsAry, param);
                Map<String, Object> updateAnMap = new HashMap<String, Object>();
                updateAnMap.put("ARCHIVE_COPY_NUM", "");
                updateAnMap.put("ARCHIVE_PAGE_NUM", "");
                updateAnMap.put("QZRQ", "");
                param = new HashMap<String, Object>();
                param.put("modleName", modleName);
                anIds = anIds01.substring(0,anIds01.lastIndexOf("','"));
                this.billDefineManagerIntfsService.updateRecordByDataIdsByIntfs(orgId, deptId, sysId, nodeId, anTableId, updateAnMap, anIds, param);
                String sqlT = " AND ID IN (";
                for (int i = 0; i < ans.length; i++) {
                    sqlT += "'" + ans[i] + "'";
                    if (i != ans.length - 1) {
                        sqlT += ",";
                    }
                }
                sqlT += ")";
                this.billDefineManagerIntfsService.updateById(sqlT,anTableId);
            }
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 移除归档列表中数据
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/deleteSubmitItemDatas")
    public ModelAndView deleteSubmitItemDatas(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String id = request.getParameter("id");
        String ids = request.getParameter("ids");
        String isAn = request.getParameter("isAn");
        String tableId = request.getParameter("tableId");
        String fileTableId = request.getParameter("fileTableId");
        String nodeId = request.getParameter("nodeId");
        String sysId = request.getParameter("sysId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        try {
            String[] idArray = ids.split(";");
            Map<String, Object> updateMap = new HashMap<String, Object>();
            Map<String, Object> param = new HashMap<String, Object>();
            updateMap.put("ARCHIVE_FLOW_STATUS", "1");
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            param.put("modleName", modleName);
            Map<String, Object> listParam = new HashMap<String, Object>();
            for (int i = 0; i < idArray.length; i++) {
                LantopSubmitItem lsi = this.deptdocarrangeService.getSubmitItemById(idArray[i], id);
                this.deptdocarrangeService.deleteSubmitItemsById(lsi);
                this.billDefineManagerIntfsService.updateRecordByDataIdWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, tableId, updateMap, idArray[i], param);
                if (null != isAn && "true".equals(isAn)) {
                    List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, fileTableId, "", "", " AND PARENT_ID = '" + idArray[i] + "'", listParam);
                    for (int j = 0; j < list.size(); j++) {
                        Map<String, Object> m = list.get(j);
                        this.billDefineManagerIntfsService.updateRecordByDataIdWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, fileTableId, updateMap, m.get("ID").toString(), param);
                    }
                }
            }
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }


    /**
     * 通过数据NODE_ID获得库表信息
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getSourceName")
    @ResponseBody
    public List<Map<String, Object>> getSourceName(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        String id = request.getParameter("id");
        List<Map<String, Object>> list = new ArrayList<>();
        try {
            list = this.deptdocarrangeService.getSourceName(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
    /**
     * 通过数据NODE_ID获得库表信息
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getSourceNames")
    @ResponseBody
    public List<Map<String, Object>> getSourceNames(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        String id = request.getParameter("id");
        List<Map<String, Object>> list = new ArrayList<>();
        try {
            list = this.deptdocarrangeService.getSourceNames(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
    /**
     * 通过数据id获得附件信息id
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getAttachIdByrecordId")
    public ModelAndView getAttachIdByRecordId(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String id = request.getParameter("id");
        try {
            List<String> list = this.deptdocarrangeService.getAttachIdByRecordId(id);
            mav.addObject("list", list);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }


    /**
     * 通过数据NODE_ID获得库表信息
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getClassNodeId")
    public ModelAndView getClassNodeId(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String id = request.getParameter("id");
        try {
            List<Map<String, Object>> list = this.deptdocarrangeService.getClassNodeId(id);
            mav.addObject("list", list);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 通过数据Org_ID获得库表信息
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getOrgId")
    public ModelAndView getOrgId(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String id = request.getParameter("id");
        String formId = request.getParameter("formId");

        try {
            Map<String,Object> attach = this.deptdocarrangeService.getOrgId(id);
            String attachId = attach.get("ID").toString();
            String tableName = attach.get("TABLE_NAME").toString();
            String tableTitle = attach.get("TABLE_TITLE").toString();
            mav.addObject("id", attachId);
            mav.addObject("tableName", tableName);
            mav.addObject("tableTitle", tableTitle);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 检查数据是否已归档
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/checkRecordSubmit")
    public ModelAndView checkRecordSubmit(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String ids = request.getParameter("ids");
        String tableId = request.getParameter("tableId");
        String sysId = request.getParameter("sysId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        Map<String, Object> listParam = new HashMap<String, Object>();
        try {
            String[] idArray = ids.split(";");
            String isSubmit = "no";
            for (int i = 0; i < idArray.length; i++) {
                String sql = " and ID = '" + idArray[i] + "' AND ARCHIVE_STATUS != '1'";
                List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, tableId, "1", "100", sql, listParam);
                if (list.size() > 0) {
                    isSubmit = "yes";
                    break;
                } else {
                    isSubmit = "no";
                }
            }
            mav.addObject("isSubmit", isSubmit);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 判断流程状态
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("checkStatus")
    public ModelAndView checkStatus(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String id = request.getParameter("id");
        try {
            String status = this.deptdocarrangeService.checkStatusById(id);
            mav.addObject("status", status);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 检查判断节点名称是否重复
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/checkNodeName")
    public ModelAndView checkNodeName(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String parentId = request.getParameter("parentId");
        String nodeName = request.getParameter("nodeName");
        String id = request.getParameter("id");
        try {
            boolean checkFlag = false;
            if ("newClass".equals(id)) {
                checkFlag = this.archiveclassmanagerService.checkNodeNameByIntfs(parentId, nodeName);
            } else {
                checkFlag = this.archiveclassmanagerService.checkNodeNameByIdByIntfs(parentId, nodeName, id);
            }
            mav.addObject("checkFlag", checkFlag);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 加载全文附件数量
     *
     * @param list
     * @throws Exception void
     * @author 钟一华
     */
    public void getAttachNum(List<Map<String, Object>> list) throws Exception {
        if (null != list) {
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> map = list.get(i);
                List<String> attach = this.deptdocarrangeService.getAttachIdByRecordId((String) map.get("ID"));
                if (null == attach || attach.size() == 0) {
                    map.put("ATTACH_SIZE", 0);
                } else {
                    map.put("ATTACH_SIZE", attach.get(2));
                }
            }
        }
    }

    /**
     * 获得目标档案库列表
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getTargetTreeNode")
    public ModelAndView getTargetTreeNode(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        // String formId = request.getParameter("formId");
        String tableId = request.getParameter("tableId");
        try {
            // String tableId = this.deptdocarrangeService.getTableIdByFormId(formId);
            List<Map<String, Object>> list = this.deptdocarrangeService.getTargetTreeNode(tableId);
            mav.addObject("rows", list);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 获得目标档案库列表
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/getTargetTreeNodeByFormId")
    public ModelAndView getTargetTreeNodeByFormId(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String formId = request.getParameter("formId");
        // String tableId = request.getParameter("tableId");
        try {
            String tableId = this.deptdocarrangeService.getTableIdByFormId(formId);
            List<Map<String, Object>> list = this.deptdocarrangeService.getTargetTreeNode(tableId);
            mav.addObject("rows", list);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 判断选中数据是否已经提交流程
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/checkRecordIsFlag")
    public ModelAndView checkRecordIsFlag(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String ids = request.getParameter("ids");
        try {
            boolean isFlag = this.deptdocarrangeService.checkRecordIsFlag(ids);
            mav.addObject("isFlag", isFlag);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 取消共享设置操作
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/updateShareStatus")
    public ModelAndView updateShareStatus(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String ids = request.getParameter("ids");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String fileTableId = request.getParameter("fileTableId");
        String sysId = request.getParameter("sysId");
        String flag = request.getParameter("flag");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        try {
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            String[] dataIds = ids.split(";");
            String sql = " AND PARENT_ID IN (";
            for (int i = 0; i < dataIds.length; i++) {
                sql += "'" + dataIds[i] + "'";
                if (i != dataIds.length - 1) {
                    sql += ",";
                }
                this.deptdocarrangeService.deleteShareDataByRecord(dataIds[i]);
            }
            sql += ")";
            Map<String, Object> updateMap = new HashMap<String, Object>();
            updateMap.put("ARCHIVE_SHARE_STATUS", "0");
            if (null != ids && ids.length() > 1) {
                Map<String, Object> param = new HashMap<String, Object>();
                param.put("ajDataId", "");
                param.put("modleName", modleName);
                this.billDefineManagerIntfsService.updateRecordByDataIdsWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, tableId, updateMap, ids, param);
            }
            ids = "";
            if (null != flag && "an".equals(flag)) {
                Map<String, Object> map = new HashMap<String, Object>();
                List<Map<String, Object>> fileList = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByNoChangeByIntfs(orgId, deptId, sysId, fileTableId, "", "", sql, map);
                for (int i = 0; i < fileList.size(); i++) {
                    Map<String, Object> fileMap = fileList.get(i);
                    this.deptdocarrangeService.deleteShareDataByRecord((String) fileMap.get("ID"));
                    ids += (String) fileMap.get("ID") + ";";
                }
            }
            if (null != ids && ids.length() > 1) {
                Map<String, Object> param = new HashMap<String, Object>();
                param.put("ajDataId", "");
                param.put("modleName", modleName);
                this.billDefineManagerIntfsService.updateRecordByDataIdsWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, fileTableId, updateMap, ids, param);
            }
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 提交部门方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/submitDept")
    public ModelAndView submitDept(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String ids = request.getParameter("ids");
        String table = request.getParameter("table");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String sysId = request.getParameter("sysId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        Map<String, Object> listParam = new HashMap<String, Object>();
        try {
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            String[] idsArray = ids.split(";");
            Map<String, Object> updateMap = new HashMap<String, Object>();
            updateMap.put("ARCHIVE_SHARE_STATUS", "2");
            // 所选节点对应物理表信息
            List<Map<String, Object>> allList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "");
            String tableName = "";
            String tableTitle = "";
            String fileTableId = "";
            String fileTableName = "";
            String fileTableTitle = "";
            if (allList.size() == 1) {
                // 文件目录标签页物理表信息
                List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "1");
                Map<String, Object> fileMap = fileList.get(0);
                tableName = fileMap.get("TABLE_NAME").toString();
                tableTitle = fileMap.get("TABLE_TITLE").toString();
            }
            if (allList.size() >= 2) {
                if (table.equals("file")) {
                    // 文件目录标签页物理表信息
                    List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "2");
                    Map<String, Object> fileMap = fileList.get(0);
                    tableName = fileMap.get("TABLE_NAME").toString();
                    tableTitle = fileMap.get("TABLE_TITLE").toString();
                } else {
                    // 文件目录标签页物理表信息
                    List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "2");
                    Map<String, Object> fileMap = fileList.get(0);
                    fileTableId = fileMap.get("ID").toString();
                    fileTableName = fileMap.get("TABLE_NAME").toString();
                    fileTableTitle = fileMap.get("TABLE_TITLE").toString();
                    // 案卷目录标签页物理表信息
                    List<Map<String, Object>> anList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "1");
                    Map<String, Object> anMap = anList.get(0);
                    tableName = anMap.get("TABLE_NAME").toString();
                    tableTitle = anMap.get("TABLE_TITLE").toString();
                }
            }
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("ajDataId", "");
            param.put("modleName", modleName);
            for (int i = 0; i < idsArray.length; i++) {
                boolean isExist = this.deptdocarrangeService.isExistFileShareByDataIdAndDeptId(idsArray[i], deptId);
                if (isExist == false) {
                    LantopFileShare lfs = new LantopFileShare();
                    List<Map<String, Object>> list = this.archiveClassManagerIntfsService.getArchiveClassListInfoByIntfs(nodeId);
                    String nodePath = "";
                    if (list.size() > 0) {
                        Map<String, Object> nodeMap = list.get(0);
                        nodePath = nodeMap.get("ARCHIVE_CLASS_NODE_PATH").toString();
                    }
                    lfs.setArchiveClassId(nodeId);
                    lfs.setArchiveClassNodePath(nodePath);
                    lfs.setArchiveTableId(tableId);
                    lfs.setArchiveTableName(tableName);
                    lfs.setArchiveTableTitle(tableTitle);
                    lfs.setOrgId(orgId);
                    lfs.setDeptId(deptId);
                    lfs.setSysId(sysId);
                    lfs.setShareDeptId(deptId);
                    lfs.setRecordId(idsArray[i]);
                    this.deptdocarrangeService.saveFileShare(lfs);
                }
                // this.billDefineManagerIntfsService.updateRecordByDataIdByIntfs(orgId, deptId, sysId, nodeId, tableId, updateMap, idsArray[i]);
                this.billDefineManagerIntfsService.updateRecordByDataIdWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, tableId, updateMap, idsArray[i], param);
            }
            if ("an".equals(table)) {
                String parentIds = "";
                for (int i = 0; i < idsArray.length; i++) {
                    parentIds += "'" + idsArray[i] + "',";
                }
                if (parentIds.length() > 0) {
                    parentIds = parentIds.substring(0, parentIds.length() - 1);
                }
                String sql = " AND PARENT_ID IN (" + parentIds + ")";
                List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
                list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, fileTableId, "1", "100", sql, listParam);
                if (list.size() > 0) {
                    String childIds = "";
                    for (int i = 0; i < list.size(); i++) {
                        Map<String, Object> fileMap = list.get(i);
                        String fileId = (String) fileMap.get("ID");
                        boolean isExist = this.deptdocarrangeService.isExistFileShareByDataIdAndDeptId(fileId, deptId);
                        if (isExist == false) {
                            LantopFileShare lfs = new LantopFileShare();
                            List<Map<String, Object>> isExistList = this.archiveClassManagerIntfsService.getArchiveClassListInfoByIntfs(nodeId);
                            String nodePath = "";
                            if (isExistList.size() > 0) {
                                Map<String, Object> nodeMap = isExistList.get(0);
                                nodePath = nodeMap.get("ARCHIVE_CLASS_NODE_PATH").toString();
                            }
                            lfs.setArchiveClassId(nodeId);
                            lfs.setArchiveClassNodePath(nodePath);
                            lfs.setArchiveTableId(fileTableId);
                            lfs.setArchiveTableName(fileTableName);
                            lfs.setArchiveTableTitle(fileTableTitle);
                            lfs.setOrgId(orgId);
                            lfs.setDeptId(deptId);
                            lfs.setSysId(sysId);
                            lfs.setShareDeptId(deptId);
                            lfs.setRecordId(fileId);
                            this.deptdocarrangeService.saveFileShare(lfs);
                        }
                        childIds += fileId + ";";
                    }
                    if (childIds.length() > 0) {
                        childIds = childIds.substring(0, childIds.length() - 1);
                    }
                    // this.billDefineManagerIntfsService.updateRecordByDataIdsByIntfs(orgId, deptId, sysId, nodeId, fileTableId, updateMap,childIds);
                    this.billDefineManagerIntfsService.updateRecordByDataIdsWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, fileTableId, updateMap, childIds, param);
                }
            }
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 粘贴操作
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/doPasteDatas")
    public ModelAndView doPasteDatas(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String targetNodeId = request.getParameter("targetNodeId");
        String sourceNodeId = request.getParameter("sourceNodeId");
        String sourceTableId = request.getParameter("sourceTableId");
        String sourceChildTableId = request.getParameter("sourceChildTableId");
        String fromType = request.getParameter("fromType");
        String dataIds = request.getParameter("dataIds");
        String operator = request.getParameter("operator");
        String selectType = request.getParameter("selectType");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        sysId = this.commSysInfoIntfsService.getSysIdByIntfs(sysId);
        String loginUserId = SessionHelper.getLoginSysUserId(request);
        String loginIp = SessionHelper.getClientIp(request);
        String sqlCondition = request.getParameter("sql");
        sqlCondition = URLDecoder.decode(sqlCondition, "utf-8");
        String zlzt = request.getParameter("zlzt");//著录状态
        try {
            // 判断是否为剪切,剪切则增加过滤条件:未归档并且未提交流程
            if ("cut".equals(operator)) {
                sqlCondition += " AND ARCHIVE_STATUS = '1' AND ARCHIVE_FLOW_STATUS = '1'";
            }
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("sqlCondition", " AND " + sqlCondition);
            params.put("ARCHIVE_SHARE_STATUS", "2");
            params.put("zlzt", zlzt);
            this.billDefineManagerIntfsService.doPasteDatasByIntfs(targetNodeId, sourceNodeId, sourceTableId, sourceChildTableId, fromType, dataIds, operator, selectType, orgId, deptId, sysId, loginUserId, loginIp, params);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 粘贴操作
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/doMoveDatas")
    public ModelAndView doMoveDatas(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String targetNodeId = request.getParameter("targetNodeId");
        String sourceNodeId = request.getParameter("sourceNodeId");
        String sourceTableId = request.getParameter("sourceTableId");
        String sourceChildTableId = request.getParameter("sourceChildTableId");
        String fromType = request.getParameter("fromType");
        String dataIds = request.getParameter("dataIds");
        String operator = request.getParameter("operator");
        String selectType = request.getParameter("selectType");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        sysId = this.commSysInfoIntfsService.getSysIdByIntfs(sysId);
        String loginUserId = SessionHelper.getLoginSysUserId(request);
        String loginIp = SessionHelper.getClientIp(request);
        try {
            String sql = " AND ARCHIVE_SHARE_STATUS = '2' AND ARCHIVE_STATUS != '3' AND (ARCHIVE_FLOW_STATUS != '2' OR ARCHIVE_FLOW_STATUS IS NULL OR ARCHIVE_FLOW_STATUS = '')";
            if (null == sourceChildTableId || "".equals(sourceChildTableId)) {
                sql += " AND (PARENT_ID IS NULL OR PARENT_ID = '')";
            }
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("sqlCondition", sql);
            params.put("ARCHIVE_SHARE_STATUS", "2");
            this.billDefineManagerIntfsService.doPasteDatasByIntfs(targetNodeId, sourceNodeId, sourceTableId, sourceChildTableId, fromType, dataIds, operator, selectType, orgId, deptId, sysId, loginUserId, loginIp, params);

            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 数据迁移操作
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/toSelectNodesJsp")
    public ModelAndView toSelectNodesJsp(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String dialogId = request.getParameter("dialogId");
        // 节点id
        String nodeId = request.getParameter("nodeId");
        // 库表id
        String tableId = request.getParameter("tableId");
        // 文件级库表id
        String fileTableId = request.getParameter("fileTableId");
        // 选择类型(全选/所选)
        String selectType = request.getParameter("selectType");
        String fromType = request.getParameter("fromType");
        // 数据ids
        String ids = request.getParameter("ids");
        String sysId = request.getParameter("sysId");
        String deptId = SessionHelper.getCurrentDeptId(request);
        try {
            List<Map<String, Object>> list = this.deptdocarrangeService.getTableDataByNodeId(nodeId, deptId);
            if (list.size() > 0) {
                Map<String, Object> map = list.get(0);
                mav.addObject("path", map.get("ARCHIVE_CLASS_NODE_PATH"));
            }
            mav.addObject("ids", ids);
            mav.addObject("fromType", fromType);
            mav.addObject("nodeId", nodeId);
            mav.addObject("tableId", tableId);
            mav.addObject("fileTableId", fileTableId);
            mav.addObject("selectType", selectType);
            mav.addObject("sysId", sysId);
            mav.addObject("dialogId", dialogId);
            mav.addObject("flag", OpResult.success.ordinal());
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeSelectNodes");
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 初始化迁移节点
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/initSelectNodes")
    public ModelAndView initSelectNodes(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String path = request.getParameter("path");
        try {
            List<TreeNode> nodes = new ArrayList<TreeNode>();
            nodes = this.deptdocarrangeService.getSelectNodesByPath(path, "ROOT");
            mav.addObject("data", nodes);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 编辑分类节点方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/editTreeNode")
    public ModelAndView editTreeNode(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String id = request.getParameter("id");
        String nodeName = request.getParameter("nodeName");
        String parentPath = request.getParameter("parentPath");
        try {
            this.archiveclassmanagerService.updateTreeNodeData(id, nodeName, parentPath);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 跳转排序页面
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     * @author 钟一华
     */
    @RequestMapping("/toOrderJsp")
    public ModelAndView toOrderJsp(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String parentId = request.getParameter("id");
        String sysId = request.getParameter("sysId");
        String dialogId = request.getParameter("dialogId");
        try {
            mav.addObject("dialogId", dialogId);
            mav.addObject("parentId", parentId);
            mav.addObject("sysId", sysId);
            mav.addObject("flag", OpResult.success.ordinal());
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeOrder");
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 获得子数据集合
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     * @author 钟一华
     */
    @RequestMapping("/getAllChildData")
    public ModelAndView getAllChildData(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String ids = request.getParameter("ids");
        String tableId = request.getParameter("tableId");
        // String nodeId = request.getParameter("nodeId");
        String sysId = request.getParameter("sysId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String anTableId = request.getParameter("anTableId");
        try {
            List<Map<String, Object>> childList = new ArrayList<Map<String, Object>>();
            String[] arrayIds = ids.split(";");
            String sql = " AND PARENT_ID IN (";
            for (int i = 0; i < arrayIds.length; i++) {
                sql += "'" + arrayIds[i] + "'";
                if (i != arrayIds.length - 1) {
                    sql += ",";
                }
            }
            sql += ")";
            childList = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByNoChangeByIntfs(orgId, deptId, sysId, tableId, "", "", sql, new HashMap<String, Object>());
            if(childList.size() <= 0) {
                String[] arrayIdsT = ids.split(";");
                String sqlT = " AND ID IN (";
                for (int i = 0; i < arrayIdsT.length; i++) {
                    sqlT += "'" + arrayIdsT[i] + "'";
                    if (i != arrayIdsT.length - 1) {
                        sqlT += ",";
                    }
                }
                sqlT += ")";
                this.billDefineManagerIntfsService.updateById(sqlT,anTableId);

            }
            mav.addObject("listSize",childList.size());
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 获得目标档案库数据(只有一条数据节点时)
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     * @author 钟一华
     */
    @RequestMapping("/getTargetTreeData")
    public ModelAndView getTargetTreeData(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        // 源表id
        String sourceTableId = request.getParameter("tableId");
        String dataId = request.getParameter("id");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String nodeName = request.getParameter("nodeName");
        try {
            LantopSubmit ls = this.deptdocarrangeService.getSubmitById(dataId);
            List<Map<String, Object>> publicColList = commTableManagerIntfsService.getCbbTableAndColumnsByTabNameByIntfs(orgId, deptId, ls.getSysId(), "LANTOP_ARC_BOX_CATA"); // 公共字段
            // 获得盒目录tableId
            String boxTableId = "";
            if (publicColList.size() > 0) {
                Map<String, Object> boxMap = publicColList.get(0);
                boxTableId = (String) boxMap.get("TABLE_ID");
            }
            if (boxTableId.equals(sourceTableId)) {
                List<Map<String, Object>> fileList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, ls.getSysId(), ls.getArchiveNodeId(), "1");
                if (fileList.size() > 0) {
                    Map<String, Object> map = fileList.get(0);
                    sourceTableId = (String) map.get("ID");
                }
            }
            String targetNodeId = "";
            targetNodeId = deptdocarrangeService.getNodeIdByName(nodeName);
            if ("".equals(targetNodeId)) {
                // 获得目标档案库节点id
                targetNodeId = this.deptdocarrangeService.getTargetTreeDataBySourceTableId(sourceTableId);
            }
            mav.addObject("targetNodeId", targetNodeId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 盒目录跳转add页面
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/toAddBoxJsp")
    public ModelAndView toAddBoxJsp(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String id = request.getParameter("id");
        String dialogId = request.getParameter("dialogId");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String userId = SessionHelper.getLoginSysUserId(request);
        String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
        SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
        String orgCode = so.getOrgCode();
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("currentUserId", userId);
        param.put("currentDeptId", deptId);
        param.put("currentOrgCode", orgCode);
        param.put("nodeId", nodeId);
        Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
        param.put("languageCode", sessionLanguageCode);

        String loginUserSecretLevel = SessionHelper.getLoginSysUser(request).getSecretLevel();
        Map<String, Object> pa = new HashMap<String, Object>();
        pa.put("languageCode", sessionLanguageCode);
        pa.put("userSecretLevel", loginUserSecretLevel);
        try {
            /***** 2015/07/25增加-郭亮-拼接条件sql *****/
            String sql = " AND NODE_ID = '" + nodeId + "' AND ARCHIVE_STATUS = '1'";// 模块固定条件sql
            Map<String, String> userAuthMap = userAuthIntfsService.getUserAuthDatasByIntfs(SessionHelper.getCurrentOrgId(request), SessionHelper.getCurrentDeptId(request), sysId, "3", userId, "LANTOP_AUTH_SERVER_USERSET", nodeId, tableId, "", null);// 权限Map
            String userAuthsql = userAuthMap.get("SQL");// 权限sql
            sql = sql + userAuthsql;// 最终条件sql
            param.put("userAuthsql", sql);
            /***** 2015/07/25增加-郭亮-拼接条件sql *****/
            List<Map<String, Object>> addBoxFieldList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, tableId, "1", id, param);
            String deptCols = this.billDefineManagerIntfsService.getSelectDialogStringByIntfs(orgId, deptId, sysId, tableId); // 查找选部门，选人的字段字符串
            Map<String, Map<String, String>> mapCode = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, tableId, "", "1", pa);// 获取字段通用代码数据//
            /***** 2016/04/22增加 wangzp 页面动态查询显示 *****/
            net.sf.json.JSONArray ja = net.sf.json.JSONArray.fromObject(addBoxFieldList);
            String jaString = ja.toString();
            mav.addObject("dataJson", jaString);
            Map<String, Object> colMap = new HashMap<String, Object>();
            colMap.put("tableId", tableId);
            colMap.put("nodeId", nodeId);
            colMap.put("sysId", sysId);
            colMap.put("flag", "1");
            colMap.put("orgId", orgId);
            colMap.put("deptId", deptId);
            Map<String, Object> dynamicMap = this.commTableManagerIntfsService.getColumnPageMap(colMap);
            dynamicMap.put("MODEL_CODE", "deptdocarrangeAddBox");
            dynamicMap.put("FORM_CODE", "addBoxForm");
            String addHtml = this.billDefineDynamicService.getDynamicAddHtml(addBoxFieldList, mapCode, dynamicMap);
            mav.addObject("addHtml", addHtml);

            // 查找字段生成方式为通用代码的集合
            mav.addObject("mapCode", mapCode);
            mav.addObject("deptCols", deptCols);
            mav.addObject("addBoxFieldList", addBoxFieldList);
            mav.addObject("nodeId", nodeId);
            mav.addObject("sysId", sysId);
            mav.addObject("tableId", tableId);
            mav.addObject("dialogId", dialogId);
            mav.addObject("sysFlag", sysFlag);
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeAddBox");
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 盒目录著录方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/saveBoxDatas")
    public ModelAndView saveBoxDatas(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        Map<String, Object> map = JsonUtils.newInstance().Json2Bean2Form(request.getParameter("datas"), HashMap.class);
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String loginUserId = SessionHelper.getLoginSysUserId(request);
        String loginIp = SessionHelper.getClientIp(request);
        map.put("ORG_ID", orgId);
        map.put("DEPT_ID", deptId);
        map.put("SYS_ID", sysId);
        map.put("NODE_ID", nodeId);
        map.put("ARCHIVE_STATUS", "1");
        map.put("ARCHIVE_FLOW_STATUS", "1");
        map.put("ARCHIVE_SHARE_STATUS", "2");
        try {
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            map.put("modleName", modleName);

            Map<String, Object> getIndex = new HashMap<String, Object>();
            getIndex.put("sysId", sysId);
            getIndex.put("orgId", orgId);
            getIndex.put("deptId", deptId);
            getIndex.put("nodeId", nodeId);
            getIndex.put("tableId", tableId);
            getIndex.put("mapObj", map);
            getIndex.put("loginUserId", loginUserId);
            getIndex.put("loginIp", loginIp);
            // 获取索引信息
            List<Map<String, Object>> tableIndex = commTableManagerIntfsService.getTableIndexByParam(getIndex);
            boolean isExist = false;
            String colLabels = "";
            if (null != tableIndex) {
                for (Map<String, Object> m : tableIndex) {
                    isExist = ((Boolean) m.get("isExist")).booleanValue();
                    colLabels = (String) m.get("message");
                }
            }
            if (isExist == false) {
                String resultId = this.billDefineManagerIntfsService.insertRecordByIntfs(orgId, deptId, sysId, nodeId, tableId, map, loginUserId, loginIp);
                mav.addObject("ID", resultId);
                mav.addObject("flag", OpResult.success.ordinal());
            } else {
                mav.addObject("colLabels", colLabels);
                mav.addObject("flag", OpResult.failure.ordinal());
            }

        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 跳转编辑页面方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/toEditBoxJsp")
    public ModelAndView toEditBoxJsp(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String id = request.getParameter("id");
        String dialogId = request.getParameter("dialogId");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String boxTableId = request.getParameter("boxTableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String loginUserSecretLevel = SessionHelper.getLoginSysUser(request).getSecretLevel();
        Map<String, Object> pa = new HashMap<String, Object>();
        pa.put("userSecretLevel", loginUserSecretLevel);

        Map<String, Object> param = new HashMap<String, Object>();
        param.put("nodeId", nodeId);
        try {
            Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
            param.put("languageCode", sessionLanguageCode);
            pa.put("languageCode", sessionLanguageCode);
            // 获取id对应数据
            List<Map<String, Object>> editList = this.billDefineManagerIntfsService.getEditOrDetailFieldsAndDataByIntfs(orgId, deptId, sysId, tableId, id, "1", param);
            String deptCols = this.billDefineManagerIntfsService.getSelectDialogStringByIntfs(orgId, deptId, sysId, tableId); // 查找选部门，选人的字段字符串
            Map<String, Map<String, String>> mapCode = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, tableId, id, "1", pa);// 获取字段通用代码数据//
            net.sf.json.JSONArray ja = net.sf.json.JSONArray.fromObject(editList);
            String jaString = ja.toString();
            mav.addObject("dataJson", jaString);
            Map<String, Object> colMap = new HashMap<String, Object>();
            colMap.put("tableId", tableId);
            colMap.put("nodeId", nodeId);
            colMap.put("sysId", sysId);
            colMap.put("flag", "1");
            colMap.put("orgId", orgId);
            colMap.put("deptId", deptId);
            Map<String, Object> dynamicMap = this.commTableManagerIntfsService.getColumnPageMap(colMap);
            dynamicMap.put("MODEL_CODE", "deptdocarrangeEditBox"); // 取对应的 mydocmanagerEditFile.jsp 文件名称
            dynamicMap.put("FORM_CODE", "editFileForm");
            String editHtml = this.billDefineDynamicService.getDynamicEditHtml(editList, mapCode, dynamicMap);
            mav.addObject("editHtml", editHtml);

            mav.addObject("mapCode", mapCode);
            mav.addObject("deptCols", deptCols);
            mav.addObject("form_id", id);
            mav.addObject("mongoId", "LANTOP");
            mav.addObject("sysId", sysId);
            mav.addObject("id", id);
            mav.addObject("editList", editList);
            mav.addObject("nodeId", nodeId);
            mav.addObject("tableId", tableId);
            mav.addObject("dialogId", dialogId);
            mav.addObject("boxTableId", boxTableId);
            mav.addObject("sysFlag", sysFlag);
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeEditBox");
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 跳转详细页面方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/toDetailBoxJsp")
    public ModelAndView toDetailBoxJsp(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String id = request.getParameter("id");
        String dialogId = request.getParameter("dialogId");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String loginUserSecretLevel = SessionHelper.getLoginSysUser(request).getSecretLevel();
        Map<String, Object> pa = new HashMap<String, Object>();
        pa.put("userSecretLevel", loginUserSecretLevel);
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("nodeId", nodeId);
        try {
            Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
            param.put("languageCode", sessionLanguageCode);
            pa.put("languageCode", sessionLanguageCode);
            // 获取id对应数据
            List<Map<String, Object>> editList = this.billDefineManagerIntfsService.getEditOrDetailFieldsAndDataByIntfs(orgId, deptId, sysId, tableId, id, "3", param);
            String deptCols = this.billDefineManagerIntfsService.getSelectDialogStringByIntfs(orgId, deptId, sysId, tableId); // 查找选部门，选人的字段字符串
            Map<String, Map<String, String>> mapCode = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, tableId, id, "3", pa);// 获取字段通用代码数据//
            /***** 2016/04/13增加 wangzp 页面动态显示 *****/
            // List<Map<String, Object>> modelList = this.archiveClassManagerIntfsService.getModelData(nodeId);
            // String modelId = "";
            // if (modelList.size() > 0) {
            // modelId = (String) modelList.get(0).get("ID");
            // }
            Map<String, Object> colMap = new HashMap<String, Object>();
            colMap.put("tableId", tableId);
            colMap.put("nodeId", nodeId);
            colMap.put("sysId", sysId);
            colMap.put("flag", "3");
            colMap.put("orgId", orgId);
            colMap.put("deptId", deptId);
            Map<String, Object> dynamicMap = this.commTableManagerIntfsService.getColumnPageMap(colMap);
            dynamicMap.put("MODEL_CODE", "deptdocarrangeDetailBox");
            dynamicMap.put("FORM_CODE", "detailAnForm");
            String detailHtml = this.billDefineDynamicService.getDynamicDetailHtml(editList, mapCode, dynamicMap);
            mav.addObject("detailHtml", detailHtml);

            mav.addObject("mapCode", mapCode);
            mav.addObject("deptCols", deptCols);
            mav.addObject("form_id", id);
            mav.addObject("mongoId", "LANTOP");
            mav.addObject("sysId", sysId);
            mav.addObject("id", id);
            mav.addObject("editList", editList);
            mav.addObject("nodeId", nodeId);
            mav.addObject("tableId", tableId);
            mav.addObject("dialogId", dialogId);
            mav.addObject("sysFlag", sysFlag);
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeDetailBox");
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 更新盒目录方法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/updateBoxDatas")
    public ModelAndView updateBoxDatas(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        Map<String, Object> map = JsonUtils.newInstance().Json2Bean2Form(request.getParameter("datas"), HashMap.class);
        String id = request.getParameter("id");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        map.put("ID", id);
        try {
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("modleName", modleName);
            this.billDefineManagerIntfsService.updateRecordByDataIdWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, tableId, map, id, param);
            mav.addObject("ID", id);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 删除盒目录选中数据
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 钟一华
     */
    @RequestMapping("/deleteBoxDatas")
    public ModelAndView deleteBoxDatas(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String ids = request.getParameter("ids");
        String nodeId = request.getParameter("nodeId");
        String boxTableId = request.getParameter("boxTableId");
        String fileTableId = request.getParameter("fileTableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        try {
            Map<String, Object> listParam = new HashMap<String, Object>();
            Map<String, Object> map = new HashMap<String, Object>();
            Map<String, Object> param = new HashMap<String, Object>();
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            param.put("modleName", modleName);
            // 修改子表数据状态
            String[] boxIds = ids.split(";");
            String fileIds = "";
            for (int i = 0; i < boxIds.length; i++) {
                String sql = " AND PARENT_ID = '" + boxIds[i] + "'";
                List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByNoChangeByIntfs(orgId, deptId, sysId, fileTableId, "", "", sql, listParam);
                for (int j = 0; j < list.size(); j++) {
                    Map<String, Object> mapDel = list.get(j);
                    String id = mapDel.get("ID").toString();
                    fileIds += id;
                    if (j != list.size() - 1 || i != boxIds.length - 1) {
                        fileIds += ";";
                    }
                }
                if ("".equals(fileIds)) {
                    fileIds = " ";
                }
                map.put("ARCHIVE_STATUS", 2);
                param.put("ajDataId", boxIds[i]);
                this.billDefineManagerIntfsService.updateRecordByDataIdsWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, fileTableId, map, fileIds, param);
            }
            param.put("ajDataId", "");
            this.billDefineManagerIntfsService.updateRecordByDataIdsWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, boxTableId, map, ids, param);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 生成档号
     *
     * @param request
     * @return ModelAndView
     * @throws Exception
     * @author 张坚
     */
    @RequestMapping("/createArchiveNum")
    public ModelAndView createArchiveNum(HttpServletRequest request) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String sysId = request.getParameter("sysId");
        String ids = request.getParameter("ids");
        String tableId = request.getParameter("tableId");
        String selectType = request.getParameter("selectType");
        String parentId = request.getParameter("parentId");
        boolean flag = false;
        if ("all".equals(selectType)) {
            flag = true;
        }
        try {
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            String[] id = ids.split(",");
            List<String> recordList = Arrays.asList(id);
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("flag", flag);
            param.put("recordId", recordList);
            param.put("tableId", tableId);
            param.put("parentId", parentId);
            param.put("modleName", modleName);
            this.billDefineManagerIntfsService.updateRecordByArchiveCodeByIntfs(SessionHelper.getCurrentOrgId(request), SessionHelper.getCurrentDeptId(request), sysId, param);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 将纸质接收状态改为已接收
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/updatePaperReceive")
    public ModelAndView updatePaperReceive(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String sysId = request.getParameter("sysId");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String childTableId = request.getParameter("childTableId");
        String status = request.getParameter("status");
        String ids = request.getParameter("ids");
        String selectType = request.getParameter("selectType");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        try {
            Map<String, Object> param = new HashMap<String, Object>();
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            param.put("ARCHIVE_RECEIVE_STATUS", status);
            Map<String, Object> ajParam = new HashMap<String, Object>();
            ajParam.put("ajDataId", "");
            ajParam.put("modleName", modleName);
            if ("box".equals(selectType)) {
                String[] idsArray = ids.split(";");
                String sql = " AND ID IN (";
                for (int i = 0; i < idsArray.length; i++) {
                    sql += "'" + idsArray[i] + "'";
                    if (i != idsArray.length - 1) {
                        sql += ",";
                    }
                }
                sql += ")";
                List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByNoChangeByIntfs(orgId, deptId, sysId, tableId, "", "", sql, new HashMap<String, Object>());
                for (int i = 0; i < list.size(); i++) {
                    Map<String, Object> map = list.get(i);
                    String childSql = " AND PARENT_ID = '" + map.get("ID") + "'";
                    List<Map<String, Object>> childList = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByNoChangeByIntfs(orgId, deptId, sysId, childTableId, "", "", childSql, new HashMap<String, Object>());
                    String childIds = "";
                    for (int j = 0; j < childList.size(); j++) {
                        Map<String, Object> childMap = childList.get(j);
                        childIds += childMap.get("ID");
                        if (j != childList.size() - 1) {
                            childIds += ";";
                        }
                    }
                    if (!"".equals(childIds)) {
                        this.billDefineManagerIntfsService.updateRecordByDataIdsWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, childTableId, param, childIds, ajParam);
                    }
                }
            }
            this.billDefineManagerIntfsService.updateRecordByDataIdsWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, tableId, param, ids, ajParam);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 生成序号
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     */
    @RequestMapping("/createOrderNumber")
    public ModelAndView createOrderNumber(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String nodeId = request.getParameter("nodeId");
        String sysId = request.getParameter("sysId");
        String tableId = request.getParameter("tableId");
        String tableColsStr = request.getParameter("tableColsStr");
        String parentId = request.getParameter("parentId");
        String deptId = SessionHelper.getCurrentDeptId(request);
        String orgId = SessionHelper.getCurrentOrgId(request);
        try {
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            Map<String, Object> listParam = new LinkedHashMap<String, Object>();
            Map<String, String> orderMap = new LinkedHashMap<String, String>();
            JSONArray orderColsJSONArray = JSON.parseArray(tableColsStr);
            Map<String, String> orderColsMapString = new HashMap<String, String>();
            if (null != tableColsStr && !tableColsStr.equals("") && !tableColsStr.equals("null")) {
                for (int i = 0; i < orderColsJSONArray.size(); i++) {
                    String orderColsJSONString = orderColsJSONArray.get(i).toString();
                    orderColsMapString = JsonUtils.newInstance().Json2Bean2Form(orderColsJSONString, Map.class);
                    String name = orderColsMapString.get("COL_NAME");
                    String sort = orderColsMapString.get("SORT_CODE");
                    if (null != sort && !sort.equals("") && !sort.equals("null")) {
                        if (sort.equals("A")) {
                            sort = "ASC";
                        } else if (sort.equals("D")) {
                            sort = "DESC";
                        }
                    }
                    orderMap.put(name, sort);
                }
            }
            listParam.put("searchOrder", orderMap);
            String sql = " AND ARCHIVE_STATUS != '2'";
            if (null != parentId && !"".equals(parentId)) {
                sql += " AND PARENT_ID = '" + parentId + "'";
            } else {
                sql += " AND NODE_ID = '" + nodeId + "'";
            }
            List<Map<String, Object>> allOrderList = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, tableId, "", "", sql, listParam);
            Map<String, Object> param = new HashMap<String, Object>();
            Map<String, Object> datas = new HashMap<String, Object>();
            for (int i = 0; i < allOrderList.size(); i++) {
                Map<String, Object> map = allOrderList.get(i);
                String id = (String) map.get("ID");
                Map<String, Object> updateMap = new HashMap<String, Object>();
                updateMap.put("ARCHIVE_IN_NUM", i + 1);
                datas.put(id, updateMap);
            }
            param.put("dataMap", datas);
            param.put("modleName", modleName);
            this.billDefineManagerIntfsService.updateRecordByBatchByIntfs(orgId, deptId, sysId, nodeId, tableId, param);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 清空回收站文件目录信息
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     */
    @RequestMapping("/deleteForFile")
    public ModelAndView deleteForFile(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String nodeId = request.getParameter("nodeId");
        String sysId = request.getParameter("sysId");
        String tableId = request.getParameter("tableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        try {
            Map<String, Object> paramObj = new HashMap<String, Object>();
            String appId = sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String menuName = commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            paramObj.put("modleName", menuName);

            Map<String, Object> listParam = new HashMap<String, Object>();
            String sql = " AND NODE_ID = '" + nodeId + "' AND ARCHIVE_STATUS = '2' AND (PARENT_ID = '' OR PARENT_ID IS NULL)";
            List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, tableId, "", "", sql, listParam);
            String ids = "";
            List<String> idsArray = new ArrayList<String>();
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> map = list.get(i);
                ids += map.get("ID");
                idsArray.add((String) map.get("ID"));
                if (i != list.size() - 1) {
                    ids += ";";
                }
            }
            this.billDefineManagerIntfsService.deleteRecordByDataIdsByIntfs(orgId, deptId, sysId, nodeId, tableId, ids, paramObj);
            this.billDefineManagerIntfsService.deleteAttachmentByDataIdsByIntfs(idsArray, sysId);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 清空回收站文件目录信息
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     */
    @RequestMapping("/deleteForAn")
    public ModelAndView deleteForAn(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String nodeId = request.getParameter("nodeId");
        String sysId = request.getParameter("sysId");
        String tableId = request.getParameter("tableId");
        String childTableId = request.getParameter("childTableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        try {
            Map<String, Object> paramObj = new HashMap<String, Object>();
            String appId = sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String menuName = commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            paramObj.put("modleName", menuName);
            // 获取案卷级数据集合
            Map<String, Object> listParam = new HashMap<String, Object>();
            String sql = " AND NODE_ID = '" + nodeId + "' AND ARCHIVE_STATUS = '2'";
            List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, tableId, "", "", sql, listParam);
            String ids = "";
            List<String> idsArray = new ArrayList<String>();
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> map = list.get(i);
                String id = (String) map.get("ID");
                ids += id;
                idsArray.add(id);
                if (i != list.size() - 1) {
                    ids += ";";
                }
                // 获取案卷级下的子数据集合
                String childSql = " AND PARENT_ID = '" + id + "'";
                List<Map<String, Object>> childList = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, childTableId, "", "", childSql, listParam);
                String childIds = "";
                List<String> childIdsArray = new ArrayList<String>();
                for (int j = 0; j < childList.size(); j++) {
                    Map<String, Object> childMap = childList.get(j);
                    String childId = (String) childMap.get("ID");
                    childIds += childId;
                    childIdsArray.add(childId);
                    if (i != childList.size() - 1) {
                        childIds += ";";
                    }
                }
                this.billDefineManagerIntfsService.deleteRecordByDataIdsByIntfs(orgId, deptId, sysId, nodeId, childTableId, childIds, paramObj);
                this.billDefineManagerIntfsService.deleteAttachmentByDataIdsByIntfs(childIdsArray, sysId);
            }
            this.billDefineManagerIntfsService.deleteRecordByDataIdsByIntfs(orgId, deptId, sysId, nodeId, tableId, ids, paramObj);
            this.billDefineManagerIntfsService.deleteAttachmentByDataIdsByIntfs(idsArray, sysId);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 跳转特殊编辑页面
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     */
    @RequestMapping("/toEditAllDataJsp")
    public ModelAndView toEditAllDataJsp(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String dialogId = request.getParameter("dialogId");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String sysId = request.getParameter("sysId");
        String srcFlag = request.getParameter("srcFlag");
        String sysFlag = request.getParameter("sysFlag");
        String mid = request.getParameter("mid");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        try {
            String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
            SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
            String orgCode = so.getOrgCode();
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("currentUserId", SessionHelper.getLoginSysUserId(request));
            param.put("currentDeptId", deptId);
            param.put("currentOrgCode", orgCode);
            param.put("nodeId", nodeId);
            Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
            param.put("languageCode", sessionLanguageCode);

            String loginUserSecretLevel = SessionHelper.getLoginSysUser(request).getSecretLevel();
            Map<String, Object> pa = new HashMap<String, Object>();
            pa.put("languageCode", sessionLanguageCode);
            pa.put("userSecretLevel", loginUserSecretLevel);
            List<Map<String, Object>> addFileFieldList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, tableId, "1", "", param);
            String deptCols = this.billDefineManagerIntfsService.getSelectDialogStringByIntfs(orgId, deptId, sysId, tableId); // 查找选部门，选人的字段字符串
            Map<String, Map<String, String>> mapCode = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, tableId, "", "1", pa);// 获取字段通用代码数据//
            /***** 2016/04/13增加 wangzp 页面动态显示 *****/
            Map<String, Object> colMap = new HashMap<String, Object>();
            colMap.put("tableId", tableId);
            colMap.put("nodeId", nodeId);
            colMap.put("sysId", sysId);
            colMap.put("flag", "1");
            colMap.put("orgId", orgId);
            colMap.put("deptId", deptId);
            Map<String, Object> dynamicMap = this.commTableManagerIntfsService.getColumnPageMap(colMap);
            dynamicMap.put("MODEL_CODE", "deptdocarrangeAddFile");
            dynamicMap.put("FORM_CODE", "addFileForm");
            String addHtml = this.billDefineDynamicService.getDynamicAddHtml(addFileFieldList, mapCode, dynamicMap);
            mav.addObject("addHtml", addHtml);
            mav.addObject("tableId", tableId);
            mav.addObject("nodeId", nodeId);
            mav.addObject("sysId", sysId);
            mav.addObject("mapCode", mapCode);
            mav.addObject("deptCols", deptCols);
            mav.addObject("srcFlag", srcFlag);
            mav.addObject("sysFlag", sysFlag);
            mav.addObject("mid", mid);
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeEditAll");
            mav.addObject("dialogId", dialogId);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    @RequestMapping("/getEditAllDataGird")
    public ModelAndView getEditAllDataGird(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
        SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
        String orgCode = so.getOrgCode();
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("currentUserId", SessionHelper.getLoginSysUserId(request));
        param.put("currentDeptId", deptId);
        param.put("currentOrgCode", orgCode);
        param.put("nodeId", nodeId);
        Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
        param.put("languageCode", sessionLanguageCode);

        String loginUserSecretLevel = SessionHelper.getLoginSysUser(request).getSecretLevel();
        Map<String, Object> pa = new HashMap<String, Object>();
        pa.put("languageCode", sessionLanguageCode);
        pa.put("userSecretLevel", loginUserSecretLevel);
        List<Map<String, Object>> addList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, tableId, "2", "", param);
        mav.addObject("addList", addList);
        return mav;
    }

    @RequestMapping("/getAllTableListForEditAll")
    public ModelAndView getAllTableListForEditAll(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String wjh = request.getParameter("wjh");
        String tm = request.getParameter("tm");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String pageNo = request.getParameter("page");
        String pageSize = request.getParameter("rows");
        // String userId = SessionHelper.getLoginSysUserId(request);
        String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
        SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
        String orgCode = so.getOrgCode();
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("currentUserId", SessionHelper.getLoginSysUserId(request));
        param.put("currentDeptId", deptId);
        param.put("currentOrgCode", orgCode);
        param.put("nodeId", nodeId);
        Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
        param.put("languageCode", sessionLanguageCode);

        String loginUserSecretLevel = SessionHelper.getLoginSysUser(request).getSecretLevel();
        Map<String, Object> pa = new HashMap<String, Object>();
        pa.put("languageCode", sessionLanguageCode);
        pa.put("userSecretLevel", loginUserSecretLevel);
        List<Map<String, Object>> addList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, tableId, "1", "", param);
        List<String> fieldList = new ArrayList<String>();
        for (int i = 0; i < addList.size(); i++) {
            Map<String, Object> addMap = addList.get(i);
            String colName = (String) addMap.get("COL_NAME");
            fieldList.add(colName);
        }
        StringBuffer sb = new StringBuffer();
        sb.append(" AND NODE_ID = '" + nodeId + "' AND (ARCHIVE_FLOW_STATUS = '' OR ARCHIVE_FLOW_STATUS = '1' OR ARCHIVE_FLOW_STATUS IS NULL) AND (ARCHIVE_STATUS = '1' OR ARCHIVE_STATUS = '' OR ARCHIVE_STATUS IS NULL)");
        sb.append(" AND ARCHIVE_SHARE_STATUS = '2'");

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userSecretLevel", SessionHelper.getLoginSysUser(request).getSecretLevel());
        Map<String, String> map = this.userAuthIntfsService.getUserAuthDatasByIntfs(orgId, deptId, sysId, "3", SessionHelper.getLoginSysUserId(request), "LANTOP_AUTH_SERVER_USERSET", nodeId, tableId, "", param);
        String authSql = map.get("SQL");
        sb.append(authSql);
        List<Map<String, Object>> list = null;
        if (null != wjh && !"".equals(wjh)) {
            sb.append(" AND WJH LIKE '%" + wjh + "%'");
        }
        if (null != tm && !"".equals(tm)) {
            sb.append(" AND TM LIKE '%" + tm + "%'");
        }
        if (null != tableId && !"".equals(tableId)) {
            list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByIntfs(orgId, deptId, sysId, tableId, pageNo, pageSize, sb.toString());
        }
        // this.getAttachNum(list);
        // 判断是否存在库房组件接口
        if (null != storeroommanagerIntfsService) {
            // 数据ids
            String positionIds = "";
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> m = list.get(i);
                positionIds += (String) m.get("ID");
                if (i != list.size() - 1) {
                    positionIds += ",";
                }
            }
            Map<String, Object> positionMap = new HashMap<String, Object>();
            positionMap.put("IDS", positionIds);
            // 通过数据id获取存放位置map
            Map<String, Object> storeMap = this.storeroommanagerIntfsService.getStoreRoomPositionMessageByRecordIdsByIntfs(positionMap);
            // 通过数据id获取存放位置,并添加到存放位置字段中
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> m = list.get(i);
                String id = m.get("ID") + "";
                String position = storeMap.get(id) + "";
                if ("null".equals(position)) {
                    position = "";
                }
                m.put("ARCHIVE_POSITION", position);
            }
        }
        // List<Map<String, Object>> newList = new ArrayList<Map<String, Object>>();
        // for (int i = 0; i < list.size(); i++) {
        // Map<String, Object> map = list.get(i);
        // Map<String, Object> newMap = new HashMap<String, Object>();
        // for (int j = 0; j < fieldList.size(); j++) {
        // String colName = fieldList.get(j);
        // newMap.put(colName, map.get(colName));
        // }
        // newMap.put("ID", value)
        // newList.add(newMap);
        // }
        String total = "0";
        if (null != list && list.size() > 0) {
            total = list.get(0).get("ROW_COUNT") + "";
        }
        mav.addObject("total", total);
        mav.addObject("rows", list);
        return mav;
    }

    @RequestMapping("/getDataHtmlByDataId")
    public ModelAndView getDataHtmlByDataId(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String id = request.getParameter("id");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String loginUserSecretLevel = SessionHelper.getLoginSysUser(request).getSecretLevel();
        Map<String, Object> pa = new HashMap<String, Object>();
        pa.put("userSecretLevel", loginUserSecretLevel);
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("nodeId", nodeId);
        // String fields = commTableSysFieldLoader.getFields();
        try {
            Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
            param.put("languageCode", sessionLanguageCode);
            // 获取id对应数据
            List<Map<String, Object>> editList = this.billDefineManagerIntfsService.getEditOrDetailFieldsAndDataByIntfs(orgId, deptId, sysId, tableId, id, "1", param);
            Map<String, Object> dataMap = new HashMap<String, Object>();
            for (int i = 0; i < editList.size(); i++) {
                Map<String, Object> editMap = editList.get(i);
                String key = (String) editMap.get("COL_NAME");
                Object value = editMap.get("COL_VALUE");
                Object valueName = editMap.get("COL_VALUE_NAME");
                if (null != value && !"".equals(value)) {
                    // if (fields.indexOf(key) != -1) {
                    // if (key.indexOf("USER") != -1) {
                    // dataMap.put(key, userLoader.getSysUserById(value + "").getName());
                    // } else if (key.indexOf("DEPT") != -1) {
                    // dataMap.put(key, deptLoader.getSysDeptTl(value + "", "zh_CN").getDeptName());
                    // }
                    // dataMap.put(key + "_ID", value);
                    // } else {
                    dataMap.put(key, value);
                    dataMap.put(key + "NAME", valueName);
                    // }
                }
            }
            mav.addObject("dataMap", dataMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 跳转条件筛选页面
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     */
    @RequestMapping("/toSelectConditionJsp")
    public ModelAndView toSelectConditionJsp(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String dialogId = request.getParameter("dialogId");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String sysId = request.getParameter("sysId");
        String openType = request.getParameter("openType");
        String tableName = request.getParameter("tableName");
        String loginUserSecretLevel = SessionHelper.getLoginSysUser(request).getSecretLevel();
        Map<String, Object> pa = new HashMap<String, Object>();
        pa.put("userSecretLevel", loginUserSecretLevel);
        mav.addObject("dialogId", dialogId);
        mav.addObject("nodeId", nodeId);
        mav.addObject("tableId", tableId);
        mav.addObject("sysId", sysId);
        mav.addObject("openType", openType);
        mav.addObject("tableName", tableName);
        mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeSelectCondition");
        return mav;
    }

    /**
     * 获取通用代码
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     */
    @RequestMapping("/getLookupCodeList")
    public ModelAndView getLookupCodeList(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        String tableId = request.getParameter("tableId");
        String nodeId = request.getParameter("nodeId");
        String userId = SessionHelper.getLoginSysUserId(request);
        SysLookupSimpleVo ssv = new SysLookupSimpleVo();
        ssv.setLookupCode("");
        ssv.setLookupName("---请选择---");
        // 获取字段通用代码数据
        Collection<SysLookupSimpleVo> jtbQzh = upLoader.getLookUpListByType("LANTOP_JTB_QZH");
        Collection<SysLookupSimpleVo> jtbQzhList = new ArrayList<SysLookupSimpleVo>();
        jtbQzhList.add(ssv);
        jtbQzhList.addAll(jtbQzh);
        String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
        SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
        String orgCode = so.getOrgCode();
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("currentUserId", userId);
        param.put("currentDeptId", deptId);
        param.put("currentOrgCode", orgCode);
        param.put("nodeId", nodeId);
        Collection<SysLookupSimpleVo> limitList = new ArrayList<SysLookupSimpleVo>();
        Map<String, Map<String, String>> mm = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, tableId, "", "0");
        Map<String, String> m = mm.get("ARCHIVE_MANA_PERIOD");
        Iterator<String> it = m.keySet().iterator();
        while (it.hasNext()) {
            String key = it.next();
            SysLookupSimpleVo slsv = new SysLookupSimpleVo();
            slsv.setLookupCode(key);
            slsv.setLookupName(m.get(key));
            limitList.add(slsv);
        }
        mav.addObject("jtbQzh", jtbQzhList);
        mav.addObject("limit", limitList);
        return mav;
    }

    /**
     * 获取条件查询sql
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     */
    @RequestMapping("/getSelectDataSql")
    public ModelAndView getSelectDataSql(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String sysId = request.getParameter("sysId");
        String tableName = request.getParameter("tableName");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        // String userId = SessionHelper.getLoginSysUserId(request);
        String data = request.getParameter("dataVo");
        Map<String, Object> map = JsonUtils.newInstance().Json2Bean2Form(data, HashMap.class);
        StringBuffer sb = new StringBuffer();
        StringBuffer printSb = new StringBuffer();
        sb.append(" AND NODE_ID = '" + nodeId + "' AND (PARENT_ID = '' OR PARENT_ID IS NULL) AND (ARCHIVE_STATUS = '1' OR ARCHIVE_STATUS IS NULL OR ARCHIVE_STATUS = '')");
        printSb.append(" " + tableName + ".NODE_ID = '" + nodeId + "' AND ( " + tableName + ".PARENT_ID = '' OR  " + tableName + ".PARENT_ID IS NULL) AND ( " + tableName + ".ARCHIVE_STATUS = '1' OR  " + tableName + ".ARCHIVE_STATUS IS NULL)");

        sb.append(" AND ARCHIVE_SHARE_STATUS = '2'");
        printSb.append(" AND " + tableName + ".ARCHIVE_SHARE_STATUS = '2'");

        // 添加过滤条件
        // 归档年度
        if (null != map.get("YEAR") && !"".equals(map.get("YEAR"))) {
            sb.append(" AND YEAR = '" + map.get("YEAR") + "'");
            printSb.append(" AND " + tableName + ".YEAR = '" + map.get("YEAR") + "'");
        }
        // 保管期限
        if (null != map.get("ARCHIVE_MANA_PERIOD") && !"".equals(map.get("ARCHIVE_MANA_PERIOD"))) {
            sb.append(" AND ARCHIVE_MANA_PERIOD = '" + map.get("ARCHIVE_MANA_PERIOD") + "'");
            printSb.append(" AND " + tableName + ".ARCHIVE_MANA_PERIOD = '" + map.get("ARCHIVE_MANA_PERIOD") + "'");
        }
        // 全宗号
        if (null != map.get("QZH") && !"".equals(map.get("QZH"))) {
            sb.append(" AND QZH = '" + map.get("QZH") + "'");
            printSb.append(" AND " + tableName + ".QZH = '" + map.get("QZH") + "'");
        }
        boolean convertNumFlag = false;
        // 档号范围
        if (null != map.get("ARCHIVE_CODE_START") && !"".equals(map.get("ARCHIVE_CODE_START")) && null != map.get("ARCHIVE_CODE_END") && !"".equals(map.get("ARCHIVE_CODE_END"))) {
            String archiveCodeStart = (String) map.get("ARCHIVE_CODE_START");
            int lastIndex = archiveCodeStart.lastIndexOf("-");
            if (lastIndex > 0) {
                String topString = archiveCodeStart.substring(0, lastIndex);
                String endString = archiveCodeStart.substring(lastIndex + 1);
                String archiveCodeEnd = (String) map.get("ARCHIVE_CODE_END");
                long topNum = 0;
                long endNum = 0;
                if (StringUtils.isNumeric(endString) && StringUtils.isNumeric(archiveCodeEnd)) {
                    convertNumFlag = true;
                    topNum = Long.parseLong(endString);
                    endNum = Long.parseLong(archiveCodeEnd);
                    sb.append(" AND SUBSTR(ARCHIVE_CODE, 0, " + lastIndex + ") = '" + topString + "' AND CAST(SUBSTR(ARCHIVE_CODE, " + (lastIndex + 2) + ") AS decimal(18)) between " + topNum + " and " + endNum + "");
                    printSb.append(" AND SUBSTR(" + tableName + ".ARCHIVE_CODE, 0, " + lastIndex + ") = '" + topString + "' AND CAST(SUBSTR(" + tableName + ".ARCHIVE_CODE, " + (lastIndex + 2) + ") AS decimal(18)) between " + topNum + " and " + endNum + "");
                }
            } else {
                convertNumFlag = false;
            }
        } else {
            convertNumFlag = true;
        }
        // 盒号
        if (null != map.get("ARCHIVE_BOX_CODE") && !"".equals(map.get("ARCHIVE_BOX_CODE"))) {
            sb.append(" AND ARCHIVE_BOX_CODE = '" + map.get("ARCHIVE_BOX_CODE") + "'");
            printSb.append(" AND " + tableName + ".ARCHIVE_BOX_CODE = '" + map.get("ARCHIVE_BOX_CODE") + "'");
        }
        if (!convertNumFlag) {
            mav.addObject("flag", false);
            mav.addObject("msg", "档号范围输入有误，无法进行范围查询！");
        } else {
            mav.addObject("flag", true);
            Map<String, Object> listParam = new LinkedHashMap<String, Object>();
            List<Map<String, Object>> dataList = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, tableId, "", "", sb.toString(), listParam);
            if (dataList.size() > 0) {
                mav.addObject("selectSql", sb.toString());
                mav.addObject("reportSql", printSb.toString());
            } else {
                mav.addObject("flag", false);
                mav.addObject("msg", "按输入条件，未查询到数据！");
            }
        }
        return mav;
    }

    /**
     * 文件著录退回操作
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     */
    @RequestMapping("/updateRecordForBackData")
    public ModelAndView updateRecordForBackData(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String sysId = request.getParameter("sysId");
        sysId = this.commSysInfoIntfsService.getSysIdByIntfs(sysId);
        String ids = request.getParameter("ids");
        String nodeId = request.getParameter("nodeId");
        String tableId = request.getParameter("tableId");
        String childTableId = request.getParameter("childTableId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        try {
            String appId = this.sysApplicationAPI.getCurrentAppId();
            String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
            String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
            Map<String, Object> updateMap = new HashMap<String, Object>();
            updateMap.put("ARCHIVE_SHARE_STATUS", "0");
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("ajDataId", "");
            param.put("modleName", modleName);
            this.billDefineManagerIntfsService.updateRecordByDataIdsWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, tableId, updateMap, ids, param);
            if (null != childTableId && !"".equals(childTableId)) {
                String[] idArray = ids.split(";");
                String sql = " AND PARENT_ID IN (";
                for (int i = 0; i < idArray.length; i++) {
                    sql += "'" + idArray[i] + "'";
                    if (i != idArray.length - 1) {
                        sql += ",";
                    }
                }
                sql += ")";
                Map<String, Object> map = new HashMap<String, Object>();
                List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByNoChangeByIntfs(orgId, deptId, sysId, tableId, "", "", sql, map);
                if (list.size() > 0) {
                    String childIds = "";
                    for (int i = 0; i < list.size(); i++) {
                        Map<String, Object> m = list.get(i);
                        childIds += m.get("ID");
                        if (i != list.size() - 1) {
                            childIds += ";";
                        }
                    }
                    this.billDefineManagerIntfsService.updateRecordByDataIdsWithUpdateAjByIntfs(orgId, deptId, sysId, nodeId, childTableId, updateMap, childIds, param);
                }
            }
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 检查数据是否合法
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     */
    @RequestMapping("/checkDatasByParam")
    public ModelAndView checkDatasByParam(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String tableId = request.getParameter("tableId");
        String sysId = request.getParameter("sysId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sqlWhere = request.getParameter("sqlWhere");
        sqlWhere = URLDecoder.decode(URLDecoder.decode(sqlWhere, "utf-8"), "utf-8");
        Map<String, Object> updateMap = new HashMap<String, Object>();
        List<Map<String, Object>> list = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByNoChangeByIntfs(orgId, deptId, sysId, tableId, "", "", " AND " + sqlWhere, updateMap);
        boolean isHave = false;
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> map = list.get(i);
            // 判断是否已归档
            if (null != map.get("ARCHIVE_STATUS") && "3".equals(map.get("ARCHIVE_STATUS"))) {
                isHave = true;
                break;
            }
            if (null != map.get("ARCHIVE_FLOW_STATUS") && "2".equals(map.get("ARCHIVE_FLOW_STATUS"))) {
                isHave = true;
                break;
            }
        }
        mav.addObject("isHave", isHave);
        return mav;
    }

    /**
     * 判断是否有唯一索引
     */
    @RequestMapping("/isHaveIndex")
    public ModelAndView isHaveIndex(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String sysId = request.getParameter("sysId");
        String tableId = request.getParameter("tableId");
        String flag = request.getParameter("flag");
        String orgId = request.getParameter("orgId");
        String deptId = request.getParameter("deptId");
        Map<String, Object> getIndex = new HashMap<String, Object>();
        getIndex.put("orgId", orgId);
        getIndex.put("deptId", deptId);
        getIndex.put("sysId", sysId);
        getIndex.put("tableId", tableId);
        getIndex.put("flag", flag);
        // 获取索引信息
        List<Map<String, Object>> tableIndex = commTableManagerIntfsService.getTableIndexByParam(getIndex);
        if (null != tableIndex) {
            for (Map<String, Object> m : tableIndex) {
                String isHave = (String) m.get("isHave");// 1,不存在唯一索引 2,存在唯一索引
                mav.addObject("isHave", isHave);
            }
        }
        return mav;
    }

    /**
     * 部门文件管理流程后处理 之前做唯一索引判断
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     */
    @RequestMapping("/beforeNotify")
    public ModelAndView beforeNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String formId = request.getParameter("id");
        String nodeId = request.getParameter("nodeId");
        Map<String, Object> resultMap = deptdocarrangeService.beforeNotify(formId, nodeId);
        mav.addObject("resultMap", resultMap);
        return mav;
    }

    /**
     * 根据菜单启用控制退回按钮显隐
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 张祖明
     */
    @RequestMapping("/accessButtions")
    public ModelAndView accessButtions(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setView(null);
        String status = "1";// 启用
        String appId = sysApplicationAPI.getCurrentAppId();
        SysMenu sysMenu = menuAPI.getSysMenuByCode("lantop_mydocarrange", appId);
        status = sysMenu.getStatus();
        String url = sysMenu.getUrl();
        if (url.equals("") || url == null) {
            status = "0";
        }

        mav.addObject("status", status);
        mav.addObject("flag", OpResult.success.ordinal());
        return mav;
    }


    /**
     * 跳转迁移页面
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 张余
     */
    @RequestMapping("/toMigrationFileJsp")
    public ModelAndView toMigrationFileJsp(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        String dialogId = request.getParameter("dialogId");// 面板ID
        String ids = request.getParameter("ids");// 数据id串
        String tableId = request.getParameter("tableId");// 迁移的表ID
        String fileType = request.getParameter("fileType");// 迁移数据类型，file 文件级；an 案卷级 ； box 盒级
        String nodeId = request.getParameter("nodeId");// 节点id
        String sysId = request.getParameter("sysId");// 系统id
        //zcl 2019-08-31 标识迁移状态  0整理归档  1档案整理
        String archiveStatus = request.getParameter("archiveStatus");
        mav.addObject("dialogId", dialogId);
        mav.addObject("ids", ids);
        mav.addObject("tableId", tableId);
        mav.addObject("fileType", fileType);
        mav.addObject("nodeId", nodeId);
        mav.addObject("sysId", sysId);
        mav.addObject("archiveStatus", archiveStatus);
        if(archiveStatus.equals("0")){
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/IdeptdocarrangeMigrationFile");
        }else{
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeMigrationFile");
        }
        return mav;
    }

    /**
     * 迁移数据
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 张余
     */
    @RequestMapping("/migrationData")
    public ModelAndView migrationData(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String ids = request.getParameter("ids");// 数据id串
        String tableId = request.getParameter("tableId");// 迁移的表ID
        String fileType = request.getParameter("fileType");// 迁移数据类型，file 文件级；an 案卷级 ； box 盒级
        String sourceNodeId = request.getParameter("nodeId");// 源数据节点id
        String sysId = request.getParameter("sysId");// 系统id
        String isRetain = request.getParameter("isRetain");// 是否保留原记录 no 不保留；yes 保留；
        String tgtNodeId = request.getParameter("migrationNodeId");// 迁移到目标节点ID
        String orgId = SessionHelper.getCurrentOrgId(request);// 组织ID
        String deptId = SessionHelper.getCurrentDeptId(request);// 部门ID
        String userId = SessionHelper.getLoginSysUserId(request);// 当前登陆用户ID
        String ip = SessionHelper.getClientIp(request);// 当前登陆人IP
        //zcl 2019-08-31 标识迁移状态  0整理归档  1档案整理
        String archiveStatus = request.getParameter("archiveStatus");
        String migrationType = request.getParameter("migrationType");
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("ids", ids);
        params.put("tableId", tableId);
        params.put("fileType", fileType);
        params.put("sourceNodeId", sourceNodeId);
        params.put("isRetain", isRetain);
        params.put("tgtNodeId", tgtNodeId);
        params.put("sysId", sysId);
        params.put("orgId", orgId);
        params.put("deptId", deptId);
        params.put("userId", userId);
        params.put("ip", ip);
        params.put("version", "0");// 默认版本号未0
        params.put("archiveStatus", archiveStatus);

        try {
            // 数据迁移
            String msg = deptdocarrangeService.migrationData(sysId, orgId, deptId, params, migrationType);
            mav.addObject("msg", msg);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 初始化部门文件迁移字段对应库
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 张余
     */
    @RequestMapping("/initDeptFileTree")
    public ModelAndView initDeptFileTree(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String tableId = request.getParameter("tableId");
        String orgId = SessionHelper.getCurrentOrgId(request);// 组织ID
        List<TreeNode> nodes = new ArrayList<TreeNode>();
        try {

            Map<String, Object> param = new HashMap<String, Object>();
            param.put("nodeCount", 0);
            param.put("orgId", orgId);
            nodes = this.deptdocarrangeService.initDeptFileTree(tableId, param);
            mav.addObject("data", nodes);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 跳转件号排序页面
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 张余
     */
    @RequestMapping("/toPieceNumberJsp")
    public ModelAndView toPieceNumberJsp(HttpServletRequest request, HttpServletResponse response) throws Exception {

        ModelAndView mav = new ModelAndView();
        String id = request.getParameter("nodeId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        String sysId = request.getParameter("sysId");
        sysId = this.commSysInfoIntfsService.getSysIdByIntfs(sysId);
        String userId = SessionHelper.getLoginSysUserId(request);

        String dialogId = request.getParameter("dialogId");
        String onlyDeptSee = request.getParameter("onlyDeptSee");
        String tableId = request.getParameter("tableId");// 文件及表ID
        String fileId = request.getParameter("anTableId");// 案卷或盒级表ID
        String mid = request.getParameter("mid");
        String nodeId = request.getParameter("nodeId");
        String share = request.getParameter("share");
        String createdNum = request.getParameter("createdNum");
        String isParent = request.getParameter("isParent");
        String showFlag = request.getParameter("showFlag");
        String selectRecordId = request.getParameter("selectRecordId");

        String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
        SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
        String orgCode = so.getOrgCode();

        Map<String, Object> param = new HashMap<String, Object>();
        param.put("currentUserId", userId);
        param.put("currentDeptId", deptId);
        param.put("currentOrgCode", orgCode);
        param.put("nodeId", id);
        Object sessionLanguageCode = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
        param.put("languageCode", sessionLanguageCode);

        String loginUserSecretLevel = SessionHelper.getLoginSysUser(request).getSecretLevel();
        Map<String, Object> pa = new HashMap<String, Object>();
        pa.put("languageCode", sessionLanguageCode);
        pa.put("userSecretLevel", loginUserSecretLevel);
        try {
            // 文件动态显示字段集合
            List<Map<String, Object>> fileTableList = this.billDefineManagerIntfsService.getFieldsByConditionByIntfs(orgId, deptId, sysId, fileId, "2", "", param);
            String fileDeptCols = this.billDefineManagerIntfsService.getSelectDialogStringByIntfs(orgId, deptId, sysId, fileId); // 查找选部门，选人的字段字符串
            Map<String, Map<String, String>> fileMapCode = this.billDefineManagerIntfsService.getBillLookUpCodeByIntfs(orgId, deptId, sysId, fileId, "", "4", pa);// 获取字段通用代码数据//
            // 查找字段生成方式为通用代码的集合
            mav.addObject("fileTableSize", fileTableList.size());
            mav.addObject("fileMapCode", fileMapCode);
            mav.addObject("fileDeptCols", fileDeptCols);
            mav.addObject("fileTableList", fileTableList);
            mav.addObject("selectRecordId", selectRecordId);
            mav.addObject("showFlag", showFlag);
            mav.addObject("isParent", isParent);
            mav.addObject("createdNum", createdNum);
            mav.addObject("share", share);
            mav.addObject("sysId", sysId);
            mav.addObject("nodeId", nodeId);
            mav.addObject("mid", mid);
            mav.addObject("tableId", tableId);
            mav.addObject("onlyDeptSee", onlyDeptSee);
            mav.addObject("dialogId", dialogId);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }

        mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangePieceNumber");
        return mav;
    }

    /**
     * 件号调整保存
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @author 张余
     */
    @RequestMapping("/savePieceNumber")
    public ModelAndView savePieceNumber(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String tableId = request.getParameter("tableId");// 表Id
        String sysId = request.getParameter("sysId");// 系统id
        String orgId = SessionHelper.getCurrentOrgId(request);// 组织ID
        String deptId = SessionHelper.getCurrentDeptId(request);// 部门ID
        String params = request.getParameter("params");

        try {
            // 件号调整保存
            deptdocarrangeService.savePieceNumber(sysId, orgId, deptId, params, tableId);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }


    /**
     * 断号查询
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     */
    @RequestMapping("/disconnectNumSearch")
    public ModelAndView disconnectNumSearch(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        // 案卷ID
        String mid = request.getParameter("parentId");
        // 节点ID
        String nodeId = request.getParameter("nodeId");
        // 文件级表ID
        String tableId = request.getParameter("tableId");
        // 系统标识ID
        String sysId = request.getParameter("sysId");
        String openParam = request.getParameter("openParam"); //打开位置"dazl" 档案整理的件号调整
        String orgId = SessionHelper.getCurrentOrgId(request);// 组织ID
        String deptId = SessionHelper.getCurrentDeptId(request);// 部门ID
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("PARENT_ID", mid);
        param.put("NODE_ID", nodeId);
        param.put("TABLE_ID", tableId);
        param.put("openParam", openParam);
        Map<String, Object> resultMap = this.billDefineManagerIntfsService.getDisconnectNumByParamByIntfs(orgId, deptId, sysId, param);
        mav.addObject("resultMap", resultMap);

        return mav;
    }
    /**
     * 件内序号清空
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     */
    @RequestMapping("/clearNumber")
    public ModelAndView clearNumber(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        // 案卷ID
        String mid = request.getParameter("parentId");
        // 节点ID
        String nodeId = request.getParameter("nodeId");
        // 文件级表ID
        String tableId = request.getParameter("tableId");
        // 系统标识ID
        String sysId = request.getParameter("sysId");
        String openParam = request.getParameter("openParam"); //打开位置"dazl" 档案整理的件号调整
        String orgId = SessionHelper.getCurrentOrgId(request);// 组织ID
        String deptId = SessionHelper.getCurrentDeptId(request);// 部门ID
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("PARENT_ID", mid);
        param.put("NODE_ID", nodeId);
        param.put("TABLE_ID", tableId);
        param.put("openParam", openParam);


		/*String nodeId = "";
		if (param.containsKey("NODE_ID")) {
			nodeId = (String) param.get("NODE_ID");
		}*/
        if (param.containsKey("TABLE_ID")) {
            tableId = (String) param.get("TABLE_ID");
        }
        String parentId = "";
        if (param.containsKey("PARENT_ID")) {
            parentId = (String) param.get("PARENT_ID");
        }
        if (param.containsKey("openParam")) {
            openParam = param.get("openParam")==null?"":param.get("openParam").toString();
        }


        List<Map<String, Object>> maps = jdbcAvicit.getJdbcTemplate().queryForList("SELECT TABLE_NAME FROM cbb_tables WHERE ID='" + tableId + "'");
        String tableName = maps.get(0).get("TABLE_NAME") == null ? "" : maps.get(0).get("TABLE_NAME").toString();

        StringBuffer sbSql = new StringBuffer();
        if ("dazl".equals(openParam)){
            sbSql.append(" AND  ARCHIVE_STATUS = '1' ");
//			sbSql.append(" AND ( ARCHIVE_FLOW_STATUS = '1' OR ARCHIVE_FLOW_STATUS = '' OR ARCHIVE_FLOW_STATUS IS NULL )");
        }else if("dabg".equals(openParam)){
            sbSql.append(" AND  ARCHIVE_STATUS IN ('3','4') ");
        }else {
            sbSql.append(" AND ( ARCHIVE_STATUS = '0' OR ARCHIVE_STATUS IS NULL OR ARCHIVE_STATUS = '' )");
            sbSql.append(" AND ( ARCHIVE_FLOW_STATUS = '1' OR ARCHIVE_FLOW_STATUS = '' OR ARCHIVE_FLOW_STATUS IS NULL )");
            sbSql.append(" AND ARCHIVE_SHARE_STATUS = '2'");
        }

        jdbcAvicit.getJdbcTemplate().update(" " +
                "update " + tableName + " set ARCHIVE_IN_NUM=null WHERE PARENT_ID = '"+parentId+"' "+sbSql.toString()
                );



        return mav;
    }
    
    
    /**
     * 件内序号清空
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     */
    @RequestMapping("/clearBgh")
    public ModelAndView clearBgh(HttpServletRequest request, HttpServletResponse response) throws
            Exception {
        ModelAndView mav = new ModelAndView();
        // 案卷ID
        String mid = request.getParameter("parentId");
        // 节点ID
        String nodeId = request.getParameter("nodeId");
        // 文件级表ID
        String tableId = request.getParameter("tableId");
        // 系统标识ID
        String sysId = request.getParameter("sysId");
        String openParam = request.getParameter("openParam"); //打开位置"dazl" 档案整理的件号调整
        String orgId = SessionHelper.getCurrentOrgId(request);// 组织ID
        String deptId = SessionHelper.getCurrentDeptId(request);// 部门ID
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("PARENT_ID", mid);
        param.put("NODE_ID", nodeId);
        param.put("TABLE_ID", tableId);
        param.put("openParam", openParam);
        if (param.containsKey("TABLE_ID")) {
            tableId = (String) param.get("TABLE_ID");
        }
        String parentId = "";
        if (param.containsKey("PARENT_ID")) {
            parentId = (String) param.get("PARENT_ID");
        }
        if (param.containsKey("openParam")) {
            openParam = param.get("openParam")==null?"":param.get("openParam").toString();
        }
        List<Map<String, Object>> maps = jdbcAvicit.getJdbcTemplate().queryForList("SELECT TABLE_NAME FROM cbb_tables WHERE ID='" + tableId + "'");
        String tableName = maps.get(0).get("TABLE_NAME") == null ? "" : maps.get(0).get("TABLE_NAME").toString();
        StringBuffer sbSql = new StringBuffer();
        sbSql.append(" AND ( ARCHIVE_STATUS = '0' OR ARCHIVE_STATUS IS NULL OR ARCHIVE_STATUS = '' )");
        //sbSql.append(" AND ( ARCHIVE_FLOW_STATUS = '1' OR ARCHIVE_FLOW_STATUS = '' OR ARCHIVE_FLOW_STATUS IS NULL )");
        //sbSql.append(" AND ARCHIVE_SHARE_STATUS = '2'");
        sbSql.append(" AND ZLZT = '2'");
        sbSql.append(" AND NODE_ID = '" + nodeId + "'");
        jdbcAvicit.getJdbcTemplate().update(" " +
                "update " + tableName + " set ZLH=null WHERE 1=1 "+sbSql.toString()
                );
        return mav;
    }


    /**
     * @Author XMW
     * @Description: 获取卷内数据列表数据
     * @Param:
     * @Return:
     */
    @RequestMapping("/editArchiveNum")
    @ResponseBody
    public Map<String, Object> editArchiveNum(HttpServletRequest request, String parentId, String tableId, String
            nodeId, String sysId, String openParam, Integer page, Integer rows) {
        Map<String, Object> resultMap = deptdocarrangeService.editArchiveNum(parentId, tableId, nodeId, openParam, page, rows);
        return resultMap;
    }
    
    /**
     * 保管号排序
     * @param request
     * @param parentId
     * @param tableId
     * @param nodeId
     * @param sysId
     * @param openParam
     * @param page
     * @param rows
     * @return Map<String,Object>
     * @throws
     */
    @RequestMapping("/editZlztBgh")
    @ResponseBody
    public Map<String, Object> editZlztBgh(HttpServletRequest request, String parentId, String tableId, String
            nodeId, String sysId, String openParam, Integer page, Integer rows) {
        Map<String, Object> resultMap = deptdocarrangeService.editZlztBgh(parentId, tableId, nodeId, openParam, page, rows);
        return resultMap;
    }


    /**
     * @Author XMW
     * @Description: 保存修改后的卷内序号
     * @Param:
     * @Return:
     */
    @RequestMapping("/saveArchiveNum")
    @ResponseBody
    public Map<String, Object> saveArchiveNum(HttpServletRequest request, String tableId, String params, String
            parentId) {
        Map<String, Object> resultMap = deptdocarrangeService.saveArchiveNum(tableId, params, parentId);
        return resultMap;
    }
    
    /**
     * 保存件号调整
     * @param request
     * @param tableId
     * @param params
     * @param parentId
     * @return Map<String,Object>
     * @throws
     */
    @RequestMapping("/saveBgh")
    @ResponseBody
    public Map<String, Object> saveBgh(HttpServletRequest request, String tableId, String params, String
            parentId, String nodeId) {
        Map<String, Object> resultMap = deptdocarrangeService.saveBgh(tableId, params, parentId,nodeId);
        return resultMap;
    }


    /**
     * @Author XMW
     * @Description: 卷内序号自动排序
     * @Param:
     * @Return:
     */
    @RequestMapping("/autoArchiveSort")
    @ResponseBody
    public Map<String, Object> autoArchiveSort(HttpServletRequest request, String tableId, String sysId, String
            parentId, String openParam) {
        Map<String, Object> resultMap = deptdocarrangeService.autoArchiveSort(tableId, sysId, parentId, openParam);
        return resultMap;
    }
    
    /**
     * 件号自动排序
     * @param request
     * @param tableId
     * @param sysId
     * @param parentId
     * @param openParam
     * @return Map<String,Object>
     * @throws
     */
    @RequestMapping("/autoBghSort")
    @ResponseBody
    public Map<String, Object> autoBghSort(HttpServletRequest request, String tableId, String sysId, String
            parentId, String openParam, String nodeId) {
        Map<String, Object> resultMap = deptdocarrangeService.autoBghSort(tableId, sysId, parentId, openParam, nodeId);
        return resultMap;
    }


    /**
     * 归档查询
     *
     * @param request
     * @param response
     * @return
     * @throws Exception ModelAndView
     * @throws
     */
    @RequestMapping("/archivingView")
    public ModelAndView archivingView(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String nodeid = request.getParameter("nodeId");
        String type = request.getParameter("type");
        String tableName = request.getParameter("tableName");
        Integer page = Integer.valueOf(request.getParameter("page"));
        Integer rows = Integer.valueOf(request.getParameter("rows"));
        String lei = request.getParameter("lei");
        SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(SessionHelper.getCurrentOrgIdentity(request));
        String orgCode = so.getOrgCode();
        List<Map<String, Object>> mapList = deptdocarrangeService.getArchivingViewByNodeId(nodeid, page, rows, type, tableName, lei, orgCode);
        String pages = deptdocarrangeService.getPage(nodeid, page, rows, type, tableName, lei, orgCode);
        mav.addObject("total", pages);
        mav.addObject("rows", mapList);
        mav.setView(null);
        return mav;
    }


    @RequestMapping("/closeMerge")
    @ResponseBody
    public Map<String, Object> closeMerge(String mergeIds, String fjIdsMap,String tableId) {
        Map<String, Object> resultMap = new HashMap<>();
        String ids = "";
        int i=1;
        if(mergeIds.equals("null")||mergeIds.equals("")||mergeIds==null){
            if(!paramMap.isEmpty()){
                mergeIds = paramMap.get("mergeIds")==null?"":paramMap.get("mergeIds").toString();
            }
        }
        if(fjIdsMap.equals("null")||fjIdsMap.equals("")||fjIdsMap==null){
            if(!paramMap.isEmpty()){
                fjIdsMap = paramMap.get("fjIdsMap")==null?"":paramMap.get("fjIdsMap").toString();
            }
        }
        /*if(mergeIds==""&&fjIdsMap==""){
            return null;
        }*/
        if(!paramMap.isEmpty()){
            ids = paramMap.get("ids").toString();
        }
        try{
             i = deptdocarrangeService.closeMerge(mergeIds, fjIdsMap,tableId);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if(ids!=""&&ids!=null){
                deptdocarrangeService.updateFjtmByIds(ids,tableId);
            }
        }
        // SanXiaFiles create by zhaoxiaolong 更新对应附件题名
        resultMap.put("flag", i);
        return resultMap;
    }


    /**
     * 获取本全总下的二级部门
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("/selectDeptDataGrid")
    public ModelAndView selectDeptDataGrid(HttpServletRequest request) throws Exception {
        ModelAndView mav = new ModelAndView();
        String orgName = request.getParameter("orgName");
        String orgId = request.getParameter("orgId");
        if (null == orgId) {
            orgId = SessionHelper.getCurrentOrgId(request);
        }
        List<Map<String, Object>> mapList = deptdocarrangeService.getDeptDataGridByOrgId(orgId, orgName);
        mav.setView(null);
        mav.addObject("rows", mapList);
        return mav;
    }


    @RequestMapping("/fileRecycleSave")
    @ResponseBody
    public Map<String, Object> fileRecycleSave(HttpServletRequest request, String sysId, String nodeId, String
            fileId, String tableName) {
        Map<String, Object> resultMap = new HashMap<>();
        String orgId = SessionHelper.getCurrentOrgId(request);

        int i = deptdocarrangeService.fileRecycleSave(nodeId, fileId, tableName, sysId, orgId);
        if (i == 3) {
            resultMap.put("flag", 1);
            resultMap.put("msg", "该节点下未设置关联数据!");
        }
        if (i == 1) {
            resultMap.put("flag", 0);
            resultMap.put("msg", "关联成功!");
        }
        if (i < 0) {
            resultMap.put("flag", 2);
            resultMap.put("msg", "关联失败!");
        }
        return resultMap;
    }

    /**
     * 根据formId删除对应的待办表
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("/deleteSubmitData")
    public ModelAndView deleteSubmitData(HttpServletRequest request) throws Exception {
        String formId = request.getParameter("id");
        ModelAndView mav = new ModelAndView();
        try {
            // 查找对应的档案，将档案流程状态改回去
            deptdocarrangeService.updateArchivesStatus(formId);
            //结束主流程
            BpmOperateService bpmOperateService = SpringFactory.getBean(BpmOperateService.class);
            bpmOperateService.deleteProcessInstanceByFormId(formId);
            //删除流程时，文书类审批标题序号置为-1
            //deptdocarrangeService.updateSerialNumber(formId);
            deptdocarrangeService.delLantopSubmitAnditem(formId);
            mav.addObject("flag", "1");
        } catch (Exception e) {
            e.printStackTrace();
            mav.addObject("flag", "0");
        }
        return mav;
    }



    /**
     * 原有的人员和单位展示页面没有源码，复制源码，修改
     *
     * @param request
     * @param parameter
     * @return
     * @throws Exception
     */
    @RequestMapping({"/getOrg"})
    public ModelAndView getCurrentOrg(HttpServletRequest request, Map<String, Object> parameter) throws
            Exception {
        ModelAndView view = new ModelAndView();
        String selectType = request.getParameter("selectType");
        String singleSelect = request.getParameter("singleSelect");
        String historyData = "";
        String historyId = request.getParameter("historyId");
        String splitChar = ",";
        String languageCode = SessionHelper.getSystemDefaultLanguageCode();
        languageCode = languageCode == null ? SessionHelper.getSystemDefaultLanguageCode() : languageCode;
        HttpSession session = request.getSession();
        Boolean isAdmin = (Boolean) session.getAttribute("USER_ADMIN");
        Muti3Bean arg;
        String multipleOrg;
        String extParameter;
        if (selectType.equals("user_Comprehensive")) {
            view.setViewName("avicit/platform6/modules/system/commonpopup/ComprehensiveSelector");
            if (null != historyId && historyId.trim().length() > 0) {
                arg = new Muti3Bean();
                arg.setDto1(historyId);
                arg.setDto2(splitChar);
                arg.setDto3(languageCode);
                multipleOrg = RestClientConfig.getRestHost("sysuser") + "/api/platform6/commonselectionjsp/CommonSelectionJsp/getHistoryUsersByUserIds/v1";
                historyData = (String) RestClient.doPost(multipleOrg, arg, new GenericType<ResponseMsg<String>>() {
                }).getResponseBody();
            }

            extParameter = request.getParameter("displaySubDeptUser");
            if (extParameter == null) {
                extParameter = "";
            }

            view.addObject("displaySubDeptUser", extParameter);
        }

        if (selectType.equals("user")) {
            view.setViewName("avicit/platform6/modules/system/commonpopup/UserSelect");
            if (null != historyId && historyId.trim().length() > 0) {
                arg = new Muti3Bean();
                arg.setDto1(historyId);
                arg.setDto2(splitChar);
                arg.setDto3(languageCode);
                multipleOrg = RestClientConfig.getRestHost("sysuser") + "/api/platform6/commonselectionjsp/CommonSelectionJsp/getHistoryUsersByUserIds/v1";
                historyData = (String) RestClient.doPost(multipleOrg, arg, new GenericType<ResponseMsg<String>>() {
                }).getResponseBody();
            }

            extParameter = request.getParameter("displaySubDeptUser");
            if (extParameter == null) {
                extParameter = "";
            }

            view.addObject("displaySubDeptUser", extParameter);
        } else if (selectType.equals("deptNew")) {
            view.setViewName("avicit/platform6/modules/system/commonpopup/DeptSelectUser");
            selectType = "dept";
            if (null != historyId && historyId.trim().length() > 0) {
                arg = new Muti3Bean();
                arg.setDto1(historyId);
                arg.setDto2(splitChar);
                arg.setDto3(languageCode);
                multipleOrg = RestClientConfig.getRestHost("sysuser") + "/api/platform6/commonselectionjsp/CommonSelectionJsp/getHistoryDeptsByDeptIds/v1";
                historyData = (String) RestClient.doPost(multipleOrg, arg, new GenericType<ResponseMsg<String>>() {
                }).getResponseBody();
            }
        } else if (selectType.equals("org")) {
            view.setViewName("avicit/platform6/modules/system/commonpopup/OrgSelect");
            if (null != historyId && historyId.trim().length() > 0) {
                arg = new Muti3Bean();
                arg.setDto1(historyId);
                arg.setDto2(splitChar);
                arg.setDto3(languageCode);
                multipleOrg = RestClientConfig.getRestHost("sysuser") + "/api/platform6/commonselectionjsp/CommonSelectionJsp/getHistoryOrgsByOrgIds/v1";
                historyData = (String) RestClient.doPost(multipleOrg, arg, new GenericType<ResponseMsg<String>>() {
                }).getResponseBody();
            }
        }

        extParameter = request.getParameter("extParameter");
        if (null != extParameter && !"undefined".equals(extParameter) && extParameter.trim().length() > 0) {
            parameter.putAll(JsonUtil.parseJSON2Map(extParameter));
        }

        multipleOrg = request.getParameter("multipleOrg");
        String orgDeptJson = "";
        String url;
        ArrayList exist;
        int i;
        Node orgNode;
        List depts;
        Node dataNode;
        ArrayList children;
        if (selectType.equals("org")) {
            if ((multipleOrg == null || !multipleOrg.trim().equals("n")) && !isAdmin) {
                if (multipleOrg != null && multipleOrg.trim().equals("2")) {
                    depts = this.sysUserDeptPositionAPI.getSysDeptListBySysUserId(SessionHelper.getLoginSysUserId(request));
                    dataNode = new Node();
                    dataNode.setId("1");
                    children = new ArrayList();
                    exist = new ArrayList(depts.size());

                    for (i = 0; i < depts.size(); ++i) {
                        if (!exist.contains(((SysDept) depts.get(i)).getOrgIdentity())) {
                            orgNode = this.commonSelectionAPI.getOrgNodeBySysOrgIdWithoutDept(((SysDept) depts.get(i)).getOrgIdentity(), languageCode, selectType, parameter);
                            children.add(orgNode);
                            exist.add(((SysDept) depts.get(i)).getOrgIdentity());
                        }
                    }

                    dataNode.setChildren(children);
                    orgDeptJson = this.jsonObjectToString(dataNode);
                } else {
                    orgNode = this.commonSelectionAPI.getOrgNodeBySysOrgIdWithoutDept(SessionHelper.getCurrentOrgIdentity(request), languageCode, selectType, parameter);
                    orgDeptJson = this.jsonObjectToString(orgNode);
                }
            } else {
                Muti1Bean<Object> arg1 = new Muti1Bean();
                arg1.setDto1((Object) null);
                url = RestClientConfig.getRestHost("sysuser") + "/api/platform6/commonpopup/OrgDeptSelection/getAllOrgWithCache/v1";
                avicit.platform6.api.commonpopup.dto.TreeNode node = (avicit.platform6.api.commonpopup.dto.TreeNode) RestClient.doPost(url, arg1, new GenericType<ResponseMsg<avicit.platform6.api.commonpopup.dto.TreeNode>>() {
                }).getResponseBody();
                orgDeptJson = "[" + JsonHelper.getInstance().writeValueAsString(node) + "]";
            }
        } else {
//            Muti3Bean arg;
            Node node;
            if (isAdmin && multipleOrg != null && multipleOrg.trim().equals("2")) {
                arg = new Muti3Bean();
                arg.setDto1(languageCode);
                arg.setDto2(selectType);
                arg.setDto3(parameter);
                url = RestClientConfig.getRestHost("sysuser") + "/api/platform6/commonselectionjsp/CommonSelectionJsp/getMutilOrgTree/v1";
                node = (Node) RestClient.doPost(url, arg, new GenericType<ResponseMsg<Node>>() {
                }).getResponseBody();
                orgDeptJson = this.jsonObjectToString(node);
            } else if (isAdmin) {
                orgNode = this.commonSelectionAPI.getOrgNodeBySysOrgId(SessionHelper.getCurrentOrgIdentity(request), languageCode, selectType, parameter);
                orgDeptJson = this.jsonObjectToString(orgNode);
            } else if (multipleOrg != null && multipleOrg.trim().equals("n")) {
                arg = new Muti3Bean();
                arg.setDto1(languageCode);
                arg.setDto2(selectType);
                arg.setDto3(parameter);
                url = RestClientConfig.getRestHost("sysuser") + "/api/platform6/commonselectionjsp/CommonSelectionJsp/getMutilOrgTree/v1";
                node = (Node) RestClient.doPost(url, arg, new GenericType<ResponseMsg<Node>>() {
                }).getResponseBody();
                orgDeptJson = this.jsonObjectToString(node);
            } else if (multipleOrg != null && multipleOrg.trim().equals("2")) {
                depts = this.sysUserDeptPositionAPI.getSysDeptListBySysUserId(SessionHelper.getLoginSysUserId(request));
                dataNode = new Node();
                dataNode.setId("1");
                children = new ArrayList();
                exist = new ArrayList(depts.size());

                for (i = 0; i < depts.size(); ++i) {
                    if (!exist.contains(((SysDept) depts.get(i)).getOrgIdentity())) {
                        orgNode = this.commonSelectionAPI.getOrgNodeBySysOrgId(((SysDept) depts.get(i)).getOrgIdentity(), languageCode, selectType, parameter);
                        children.add(orgNode);
                        exist.add(((SysDept) depts.get(i)).getOrgIdentity());
                    }
                }

                dataNode.setChildren(children);
                orgDeptJson = this.jsonObjectToString(dataNode);
            } else {
                orgNode = this.commonSelectionAPI.getOrgNodeBySysOrgId(SessionHelper.getCurrentOrgIdentity(request), languageCode, selectType, parameter);
                orgDeptJson = this.jsonObjectToString(orgNode);
            }
        }

        view.addObject("orgDatajson", orgDeptJson);
        view.addObject("historyData", "[" + historyData + "]");
        view.addObject("singleSelect", singleSelect);
        view.addObject("multipleOrg", multipleOrg);
        view.addObject("extParameter", extParameter);
        return view;
    }

    private String jsonObjectToString(Node object) {
        ObjectMapper mapper = new ObjectMapper();

        try {
            if (!object.getId().equals("1")) {
                return "[" + mapper.writeValueAsString(object) + "]";
            }

            for (int i = 0; i < object.getChildren().size(); ++i) {
                ((Node) object.getChildren().get(i)).setState("open");
            }

            return mapper.writeValueAsString(object.getChildren());
        } catch (JsonGenerationException var4) {
            var4.printStackTrace();
        } catch (JsonMappingException var5) {
            var5.printStackTrace();
        } catch (IOException var6) {
            var6.printStackTrace();
        }

        return "";
    }

    @RequestMapping("/getGeneralArchiveTree")
    public ModelAndView getGeneralArchiveTree(HttpServletRequest request) throws Exception {
        ModelAndView modelAndView = new ModelAndView();
        String orgId = "ORG_ROOT";
        List<TreeNode> nodes = new ArrayList<TreeNode>();
        try {
            nodes = deptdocarrangeService.getGeneralArchiveTree(orgId);
            modelAndView.addObject("data", nodes);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return modelAndView;
    }


    @Autowired
    private ArrangeProviderService arrangeProviderService;

    @RequestMapping("/formalAllFile")
    public Map<String, Object> formalAllFile(HttpServletRequest request) {

        String tableName = "LANTOP_WS_20_WJ";
        String nodeId = "8a3c86cc6ca27b0e016ca2e1986570fc";
        String tableId = "";
        String path = System.getProperty("user.home");
        String currentDeptId = SessionHelper.getCurrentDeptId(request);
        String loginSysUserId = SessionHelper.getLoginSysUserId(request);

        Map<String, Object> param = new HashMap<>();
        param.put("tablename", tableName);
        param.put("path", path);
        param.put("orgId", "ORG_ROOT");
        param.put("deptId", currentDeptId);
        param.put("userId", loginSysUserId);
        param.put("ip", "127.0.0.1");
        param.put("nodeId", nodeId);
        param.put("tableId", tableId);

        try {
            arrangeProviderService.updateSubmitStatusByTableName(param);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping("/removeListOfApprovalRelData")
    public ModelAndView removeListOfApprovalRelData(HttpServletRequest request) {
        ModelAndView mav = new ModelAndView();
        String ids = request.getParameter("ids");
        String formId = request.getParameter("formId");
        String isAn = request.getParameter("isAn");

        try {
            deptdocarrangeService.removeLantopSubmitRelData(ids, formId, isAn);
            mav.addObject("flag", "0");
        } catch (Exception e) {
            mav.addObject("flag", "1");
            e.printStackTrace();
        }
        return mav;
    }

    @RequestMapping("/openConservationLayout")
    public ModelAndView openConservationLayout(HttpServletRequest request) {
        ModelAndView mav = new ModelAndView();
        String dialogId = request.getParameter("dialogId");
        String sysId = request.getParameter("sysId");
        String formId = request.getParameter("formId");


        String nodeId = "";
        String tableId = "";

        String sql = SqlAllClass.getSubmitSelSql(formId);
        List<Map<String, Object>> list = deptdocarrangeService.runSubmitSelList(sql);
        if (CommonFunction.listNotNull(list)){
            Map<String, Object> objectMap = list.get(0);
            nodeId = objectMap.get(VariableClass.ARCHIVE_NODE_ID).toString();
            tableId = objectMap.get(VariableClass.ARCHIVE_TABLE_ID).toString();
        }

        mav.addObject("formId", formId);
        mav.addObject("sysId", sysId);
        mav.addObject("dialogId", dialogId);
        mav.addObject("nodeId", nodeId);
        mav.addObject("tableId", tableId);
        mav.setViewName("avicit/im/lantop/docmanager/deptdocmanager/deptdocmanageFileSave");
        return mav;
    }

    @RequestMapping("/getFromValueList")
    public ModelAndView getFromValueList(HttpServletRequest request) {
        ModelAndView mav = new ModelAndView();
        String formId = request.getParameter("formId");
        Map<String,Object> objectMap = new HashMap<>();
        // SanXiaFiles create by zhaoxiaolong 增加分页
        String page = request.getParameter("page"); // 第几页
        String rows = request.getParameter("rows"); // 每页显示多少条
        if (page==null||rows==null){
            page = "1";
            rows = "20";
        }
        objectMap.put("page",page);
        objectMap.put("rows",rows);
        String orgId = SessionHelper.getCurrentOrgIdentity();

        String filterSql = "(PARENT_ID = '' OR PARENT_ID IS NULL) AND (ARCHIVE_STATUS = '0') AND (ARCHIVE_FLOW_STATUS = '1' OR ARCHIVE_FLOW_STATUS = '' OR ARCHIVE_FLOW_STATUS IS NULL) AND ARCHIVE_SHARE_STATUS = '2' AND ( 1=1 )  ORDER BY CREATION_DATE DESC";

        String sql = "SELECT * FROM LANTOP_SUBMIT LS WHERE LS.ID = '" + formId + "\'";
        
        //
        //获取参数
        String sysUserId = SessionHelper.getLoginSysUserId(request);
        String sysUserName = SessionHelper.getLoginSysUser(request).getName();
        String sysDeptId = SessionHelper.getCurrentDeptId(request);
        String orgIdentity = SessionHelper.getCurrentOrgIdentity();        
        mav.addObject("sysUserId", sysUserId);
        mav.addObject("sysUserName", sysUserName);
        mav.addObject("sysDeptId", sysDeptId);
        mav.addObject("orgIdentity", orgIdentity);
        
        List<Map<String,Object>> ListData = deptdocarrangeService.executiveProcedure(sql, filterSql,mav,objectMap);
        mav.addObject("rows", ListData);
        mav.addObject("total", ListData.size());
        return mav;
    }

    @RequestMapping("/saveDataToAll")
    public ModelAndView saveDataToAll(HttpServletRequest request){
        ModelAndView mav = new ModelAndView();

        String formId = request.getParameter("formId");
        String ids = request.getParameter("ids");
        String sysId = request.getParameter("sysId");
        String deptId = SessionHelper.getCurrentDeptId(request);
        String orgId = SessionHelper.getCurrentOrgIdentity();

        try{
            deptdocarrangeService.saveSubmitItemDataAll(formId,ids,sysId,deptId,orgId);
            mav.addObject("flag", "0");
        } catch ( Exception e ){
            mav.addObject("flag", "1");
            e.printStackTrace();
        }
        return mav;
    }

    @RequestMapping("/getAllIdsByFormId")
    public ModelAndView getAllIdsByFormId(HttpServletRequest request){
        ModelAndView mav = new ModelAndView();
        String isAn = request.getParameter("isAn");
        mav.addObject("isAn", isAn);
        try{
            String formId = request.getParameter( "formId");

            deptdocarrangeService.getAllIdsList(formId, mav);
        } catch ( Exception e ){
            e.printStackTrace();
        }
        return mav;
    }
    /**
     * 根据roleId查询审批角色是不是专职档案管理员
     *
     */
    @RequestMapping("/getRole")
    public ModelAndView getRole(HttpServletRequest request){
        ModelAndView mav = new ModelAndView();
        try{
            String roleName = request.getParameter( "roleId");
            boolean b =  deptdocarrangeService.getRole(roleName);
            mav.addObject("boolean", b);
        } catch ( Exception e ){
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 撤销跨权宗移交审批中的文档
     * @MethodName: undoCrossOverApprovalInDoc
     * @param request
     * @Return: org.springframework.web.servlet.ModelAndView
     * @Author: 屈星宇
     * @Date: 2019/9/18 15:23
     */
    @RequestMapping("/undoCrossOverApprovalInDoc")
    public ModelAndView undoCrossOverApprovalInDoc(HttpServletRequest request){
        ModelAndView mav = new ModelAndView();

        //1.获取参数
        String formId = request.getParameter("formId");
        String ids = request.getParameter("ids");

        //2.处理
        try {

            deptdocarrangeService.getDealWithBusiness(formId, ids);
            mav.addObject("flag", "0");
        } catch (SQLException e) {
            mav.addObject("flag", "1");
            e.printStackTrace();
        }

        return mav;
    }

    /**
     * 重定向至跨权宗移交添加页面
     * @MethodName: redirectInTheCompany
     * @param request
     * @Return: org.springframework.web.servlet.ModelAndView
     * @Author: 屈星宇
     * @Date: 2019/9/18 16:49
     */
    @RequestMapping("/redirectInTheCompany")
    public ModelAndView redirectInTheCompany(HttpServletRequest request){
        ModelAndView mav = new ModelAndView();

        String menuCode = request.getParameter("menuCode");
        String formId = request.getParameter("formId");
        String nodeId = request.getParameter("nodeId");

        //获取参数
        mav.addObject("menuCode", menuCode);
        mav.addObject("formId", formId);
        mav.addObject("dialogId", request.getParameter("dialogId"));
        mav.addObject("nodeId", nodeId);

        mav.setViewName("avicit/im/lantop/docmanager/deptdocmanager/deptdocmanageAcrossHaveMoreRights");

        return mav;
    }

    /**
     * 更新起止日期
     * SanxiaFiles create by zhaoxiaolong
     */
    @RequestMapping("/updateQzrq")
    public void updateQzrq(HttpServletRequest request) throws Exception {
        String archivesId = request.getParameter("anId");
        String anTableId = request.getParameter("anTableId");
        String fileTableId = request.getParameter("fileTableId");
        String nodeId = request.getParameter("nodeId");
        String orgId = SessionHelper.getCurrentOrgId(request);
        String deptId = SessionHelper.getCurrentDeptId(request);
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("modleName", "整理归档");
        billDefineManagerIntfsService.updateAjDataByWjdataByInfs(fileTableId, archivesId, orgId, deptId, "LANTOP", nodeId, "", params); // 反更新案卷统计生成
        // SanXiaFiles create by zhaoxiaolong 更新起止日期
        billDefineManagerIntfsService.UpdateQzrqByAnIdAndAnTableId(archivesId,anTableId,null);
    }

    /**
     * 获取案卷归档或入库时的文件个数
     * @param request
     * @return
     */
    @RequestMapping("/getCountJnjByPid")
    public ModelAndView getCountJnjByPid(HttpServletRequest request){
        ModelAndView mav = new ModelAndView();
        String tableName = "";
        String num = "0";
        try{
            String nodeId = request.getParameter( "nodeId");
            String tableId = request.getParameter( "tableId");
            String ids = request.getParameter( "ids");
            String sqlTableName = "SELECT TABLE_NAME FROM CBB_TABLES WHERE ID = '"+tableId+"'";
            List<Map<String, Object>> listTableName = this.jdbcAvicit.getJdbcTemplate().queryForList(sqlTableName);
            if(listTableName.size()>0) {
                tableName = (String) listTableName.get(0).get("TABLE_NAME");
                String[] split = ids.split(";");
                int i = 0;
                for(String pid:split){
                    String sql = "SELECT ID FROM "+tableName+" WHERE PARENT_ID='"+pid+"'";
                    List<Map<String, Object>> numList = this.jdbcAvicit.getJdbcTemplate().queryForList(sql);
                    i = i+numList.size();
                }
                num = String.valueOf(i);
            }
            mav.addObject("num", num);
        } catch ( Exception e ){
            e.printStackTrace();
        }
        return mav;
    }
    
    
    @RequestMapping("/toStartProcess")
    public ModelAndView toStartProcess(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String sysId = request.getParameter("sysId");
        String tm = request.getParameter("tm");
        String nodeId = request.getParameter("nodeId");
        String fileTableId = request.getParameter("fileTableId");
        String type = request.getParameter("type");
        String dataIds = request.getParameter("dataIds");
        String fileSqlWhere = request.getParameter("fileSqlWhere");
        String orgCode = request.getParameter("orgCode");
        String formCode = request.getParameter("formCode");
        try{
        	mav.addObject("sysId", sysId);
        	mav.addObject("tm", tm);
            mav.addObject("nodeId", nodeId);
            mav.addObject("fileTableId", fileTableId);
            mav.addObject("type", type);
            mav.addObject("dataIds", dataIds);
            mav.addObject("fileSqlWhere", fileSqlWhere);
            mav.addObject("orgCode", orgCode);
            mav.addObject("formCode", formCode);
            mav.setViewName("avicit/im/lantop/docmanager/deptdocarrange/deptdocarrangeIframeAdd");
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

    @RequestMapping("/getProcessNameMsg")
    public ModelAndView getProcessNameMsg(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        String sysId = request.getParameter("sysId");
        String nodeId = request.getParameter("nodeId");
        String year = request.getParameter("year");
        String fileTableId = request.getParameter("tableId");
        String deptId = SessionHelper.getCurrentDeptId(request);
        String orgId = SessionHelper.getCurrentOrgIdentity(request);
        String deptName = SessionHelper.getCurrentDeptName(request);
        String tableType = "";//是否文书
        String batch = "";//批次
        try{
            String sql = "SELECT COUNT(LAC.ID) AS NUM FROM CBB_TAB_NODE T" +
                    "  LEFT JOIN LANTOP_ARCHIVE_CLASS LAC ON LAC.ID = T.NODE_ID" +
                    " WHERE LAC.ARCHIVE_TYPE = '2' AND (LAC.ARCHIVE_CLASS_NODE_CODE = 'WS' OR" +
                    " LAC.ARCHIVE_CLASS_NODE_CODE = 'WSL') AND T.TABLE_ID = '"+fileTableId+"'";
            List<Map<String, Object>> listTableName = this.jdbcAvicit.getJdbcTemplate().queryForList(sql);
            String num = listTableName.get(0).get("NUM").toString();
            if(Integer.parseInt(num)==1){
                tableType = "1";
                String sqldept = "SELECT * FROM SYS_DEPT_V WHERE ID='"+deptId+"' AND ORG_IDENTITY='"+orgId+"'";
                List<Map<String, Object>> deptList = this.jdbcAvicit.getJdbcTemplate().queryForList(sqldept);
                String parent_dept_id = deptList.get(0).get("parent_dept_id").toString();
                if(!"-1".equals(parent_dept_id)){//处室部门要去上级部门
                    String sqldeptP = "SELECT * FROM SYS_DEPT_V WHERE ID='"+parent_dept_id+"' AND ORG_IDENTITY='"+orgId+"'";
                    List<Map<String, Object>> deptListP = this.jdbcAvicit.getJdbcTemplate().queryForList(sqldeptP);
                    deptName = deptListP.get(0).get("DEPT_NAME").toString();
                }
                String count = "SELECT DECODE(MAX(TO_NUMBER(REGEXP_REPLACE(SUBSTR(SUBMIT_TITILE, -15), '[^0-9]', ''))),'',0," +
                        " MAX(TO_NUMBER(REGEXP_REPLACE(SUBSTR(SUBMIT_TITILE, -15), '[^0-9]', '')))) + 1 AS NUMS FROM LANTOP_SUBMIT SL" +
                        " WHERE SL.SUBMIT_TITILE LIKE '"+deptName+year+"年度文书类档案(第%批)_归档流程' AND SL.DEPT_ID='"+deptId+"'";
                List<Map<String, Object>> countList = this.jdbcAvicit.getJdbcTemplate().queryForList(count);
                batch = countList.get(0).get("NUMS").toString();
                /*if(Integer.parseInt(batch)<10){
                    batch = "0"+batch;
                }*/
            } else {
                tableType = "2";
            }
            mav.addObject("sysId", sysId);
            mav.addObject("nodeId", nodeId);
            mav.addObject("fileTableId", fileTableId);
            mav.addObject("tableType", tableType);
            mav.addObject("year", year);
            mav.addObject("batch", batch);
            mav.addObject("deptName", deptName);
            mav.addObject("flag", OpResult.success.ordinal());
        } catch (Exception e) {
            mav.addObject("flag", OpResult.failure.ordinal());
            e.printStackTrace();
        }
        return mav;
    }

}